CBOJ 2023 Welcome Contest Problem 1 - Soccer League


Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

You are the director a soccer league with \(N\) teams in it. The last match was just played and you are trying to find out how many points each team has.

During the season, \(M\) games were played, the \(i\)-th game saw the \(a_i\)-th team play against the \(b_i\)-th (\(a_i \not = b_i\)). The result of the \(i\)-th game was recorded in the array \(r\). If \(r_i\) is \(1\) then the \(a_i\)-th team won, if it is \(0\) then they drew, and if \(r_i\) is -1 then the \(b_i\)-th team won.

If a team wins a game, then they gain \(3\) points, if they draw, they gain \(1\) point, and finally if they lose, they gain \(0\) points.

For all \(N\) teams, compute how many points they ended the season on.

Constraints

\(1 \le N \le 100\)

\(1 \le M \le 1000\)

\(1 \le a_i, b_i \le N \: (a_i \not = b_i)\)

\(-1 \le r_i \le 1\)

Input Specification

The first line contains two integers \(N\) and \(M\), which are the number of teams, and the number of games, respectively.

The \(i+1\)-th line contains three integers \(a_i\), \(b_i\), and \(r_i\), which are the index of the first team playing, the index of the second team playing, and the result, respectively.

Output Specification

Output \(N\) lines, where the \(i\)-th line contains the number of points the \(i\)-th team had at the end of the season.

Sample Input

4 5
2 3 -1
1 2 0
3 4 -1
3 2 1
3 2 -1

Sample Output

1
4
6
3

Explanation

Team 1: \(0\ / \ 1\ / \ 0 \implies 3 \cdot 0 + 1 \cdot 1 + 0 \cdot 0 = 1\)

Team 2: \(1\ / \ 1\ / \ 2 \implies 3 \cdot 1 + 1 \cdot 1 + 0 \cdot 2 = 4\)

Team 3: \(2\ / \ 0\ / \ 2 \implies 3 \cdot 2 + 1 \cdot 0 + 0 \cdot 2 = 6\)

Team 4: \(1\ / \ 0\ / \ 0 \implies 3 \cdot 1 + 1 \cdot 0 + 0 \cdot 2 = 3\)


Comments

There are no comments at the moment.