Graph Ordering

0

0 votes
Hard, Algorithms, Approximate, Approved
Problem

You are given oriented graph with n vertices numbered 1,2,,n and m edges ui,vi. Oriented edge goes from ui to vi. Each edge have positive weight wi. You task is to find permutation p of vertices such that total weight of edges oriented from left to right is low. More formally, you task is to minimize score(p)=i|p(ui)>p(vi)wi.

Scoring:
You score for each testcase is
100score(p)iwi.

Input Format:
First line contains two space-separated integers n,m.
Next m lines contain description of edges in format ui,vi,wi.

Output Format:
Output n space-separated integers -- permutation of 1,2,,n.

Constraints:
1n100.
1m10,000.
1ui,vin.
uivi.
1wi1,000,000,000.
Note that graph can contain multiple edges.

Test generation:
Test consist of several groups. Each group generated using the following pseudocode:

def gen(n, m):
    A = 1000000000
    print(n, m)
    for i = 0, 1, ..., m - 1:
        u = random(1, 2, ..., n)
        v = random(1, 2, ..., u - 1, u + 1, ..., n)
        w = random(1, 2, ..., A)
        print(u, v, w)
Here random(S) returns random element of S equiprobable.

Group 1:
n=100,m=100.
This group contains 10 testcases.
Group 2:
n=100,m=500.
This group contains 10 testcases.
Group 3:
n=100,m=1,000.
This group contains 10 testcases.
Group 4:
n=100,m=10,000.
This group contains 10 testcases.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

score(1,2,3)=3.

Editor Image

?