시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 1024 MB | 27 | 8 | 8 | 29.630% |
You are given a graph with n vertices and m undirected edges. The vertices are numbered from 1 to n. We number the edges in the order of their appearance in the input, starting with 1. Let for each pair of numbers of edges (i, j) for which 1 ≤ i ≤ j ≤ m, create a new graph with edges that are the edges of the original graph with numbers from i to j inclusive and for the vertices of the new graph we take all vertices of the original graph. Write program connect that finds how many of these newly created graphs are connected.
The first line of the standard input contains the values of n and m. It follows m lines in the input, each containing two integers: u and v, specifying the vertices of the corresponding edge in the original graph.
Your program should print on the standard output one integer equal to the count of newly created connected graphs.
번호 | 배점 | 제한 |
---|---|---|
1 | 5 | n ≤ 100; m ≤ 200 |
2 | 15 | n ≤ 2 000; m ≤ 5 000 |
3 | 40 | n ≤ 200 |
4 | 40 | No additional constrains |
4 4 1 2 2 4 1 3 1 4
3
The pairs of edges (i, j) for which the corresponding new graph is connected are (1, 3), (1,4) and (2,4). More precisely: