Road Development (Translated)

JOI Spring Training Camp 2014/15
Original Statement / Submission Site

Problem Statement

The country IOI consists of N cities numbered 1 through N. Professor JOI is interested in how the road network in IOI was developed.

From historical records, the following facts were discovered:

Details of each road improvement plan are as follows:

Professor JOI now wants to investigate the impact of each abandoned improvement plan. For each one, calculate how many roads would have been paved if that plan had been executed.

Task

Given the road improvement plans and their execution status, for each abandoned plan, determine how many roads would have been paved if the plan had been executed. If a new road would have been built, output -1 instead.

Input

The input consists of:

Output

For each abandoned plan, output on a separate line the number of roads that would have been paved if the plan had been executed. Output -1 if a new road would have been built.

Constraints

Subtasks

Sample Input 1

3 7
1 1 2
2 2 1
2 2 3
1 2 1
2 1 2
1 2 3
2 1 3

Sample Output 1

1
-1
0
1

Explanation of Sample Output 1

There are 3 cities in IOI. Initially, there were no roads. The road improvement plans were executed as follows:

Sample Input 2

6 8
1 1 3
1 6 1
1 2 5
2 3 6
1 3 6
1 4 1
2 4 3
2 2 5

Sample Output 2

2
1
1

Sample Input 3

7 11
1 5 1
1 6 2
1 1 3
1 3 5
1 5 7
1 4 5
1 4 1
2 1 3
2 3 7
2 4 3
2 5 6

Sample Output 3

0
1
0
-1