Undirected Graph
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 184 Accepted Submission(s): 38
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
There is an undirected graph with
n vertices and
m edges. Then Yuta does
q operations on this graph. Each operation is described by two integers
L,R (1≤L≤R≤n) and can be split into three steps:
1. Delete all the edges which have at least one vertice outside the range
[L,R].
2. Yuta wants you to tell him the number of connected component of the graph.
3. Restore the graph.
This task is too hard for Rikka to solve. Can you help her?
Input There are at most 100 testcases and there are at least 97 testcases with
n,m,q≤1000.
For each testcase, the first line contains three numbers
n,m,q (n,q≤105,m≤2×105).
Then
m lines follow. Each line contains two numbers
ui,vi (1≤ui,vi≤105) which describe an edge of the graph.
Then
q lines follows. Each line contains two numbers
Li,Ri (1≤L≤R≤n) which describe an operation.
Output For each operation you need print a single line with a single number - the answer of this operation.
Sample Input
3 3 2
1 2
1 3
2 3
1 2
1 3
Sample Output
2
1
Author XJZX
Source 2015 Multi-University Training Contest 4 題意:
給定n個點m條邊的無向圖(有自環有重邊) q個詢問
對於某個詢問 query : [l,r]
把所有的邊 形如 {u,v} u,v其中一個或者兩個都不在區間[l,r]上的 都刪除,求此時殘余圖的連通分量數。
每個詢問都是互相獨立的,也就是每個詢問都是從原圖刪除而來。
思路:
感覺很有道理的樣子,寫了一發,卡常數卡死人了。。
#pragma comment(linker, /STACK:1024000000)
#include
#include
#include
#include
#include
#include