AlgoUniversity
  • Go Back
Discussion
Maximum Common Companies :

Author

Yash Sahijwani

Difficulty Level : Medium

Submissions : 631

Asked In : Appdynamics

Marks :50

: 4 | : 3

There are $$$n$$$ friends, numbered from $$$1$$$ to $$$n$$$, who buy wholesale products from different companies. There are $$$m$$$ pairs of friends where each pair of friends is connected by the common company they buy products from. Companies are numbered from 1 to 100.

Note that if $$$a$$$ and $$$b$$$ are connected by a company $$$c$$$, and $$$b$$$ and $$$d$$$ are also connected by the company $$$c$$$, then $$$a$$$ and $$$d$$$ are also connected by the company $$$c$$$. Find the maximal product of $$$a$$$ and $$$b$$$ that share the largest group of friends which is connected by a common company.

Input

The first line of input consists of 2 space separated integers $$$-$$$ $$$n$$$ and $$$m$$$ $$$(1 \leq n,m \leq 10^5)$$$. Each of the next $$$m$$$ lines consist of 3 space separated integers $$$u$$$, $$$v$$$ and $$$w$$$, which denotes that the friends numbered $$$u$$$ and $$$v$$$ are connected by the company numbered $$$w$$$. $$$(1 \leq u,v \leq n)$$$ $$$(1 \leq w \leq 100)$$$

Output

The output should consist of a single integer $$$-$$$ the maximal product.

Example

Input
5 5
1 2 1
2 3 1
1 3 1
3 4 2
4 5 2
Output
20

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.