Power Game
Practice
2.5 (2 votes)
Graphs
Algorithms
Graph representation
Problem
60% Success 2789 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Sam and Andrea are playing a game today. On a paper, there is a connected graph drawn with \(N\) vertices and \(M\) edges. Every edge has a power assigned to it denoted by an array \(A[i]\).

In every turn, Sam & Andrea have to perform the following one by one:

  • Pick an edge which if removed will increase the number of connected components in graph.
  • Add the power of the edge picked above to the score.

If everyone played optimally, find the maximum & minimum score Sam can have if he start's the game first or second.

Input Format:

  • First line contains two space-separated integers \(N\) and \(M\)
  • Next line contains \(M\) space separated integers denoting the array \(A\).
  • Next \(M\) lines containts two space-separated integers denoting an edge.

Output Format:

Print two space-separated integers denoting the maximum & minimum score Sam can have in the game.

Constraints:

\(1 \le N, M \le 10^5 \\ 1 \le A[i] \le 10^6\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
5 votes
Tags:
AlgorithmsGraph RepresentationGraphsC++
Points:50
18 votes
Tags:
GraphsHard
Points:50
5 votes
Tags:
AlgorithmsApprovedGraphsHardOpen