# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
7896 |
2014-08-24T02:22:14 Z |
gs14004 |
간선 파괴 (GA5_destroy) |
C++ |
|
2500 ms |
1960 KB |
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int,int> pi;
vector<pi> graph[707];
int p[10005], r[10005];
void init(int n){
memset(r,0,sizeof(r));
for (int i=1; i<=n; i++) {
p[i] = i;
}
}
int find(int x){
if(p[x] == x) return x;
else return p[x] = find(p[x]);
}
void uni(int x, int y){
x = find(x);
y = find(y);
if(r[x] < r[y]) p[y] = x;
else p[x] = y;
if(r[x] == r[y]) r[x]++;
}
int n,m;
void query(int p, int q){
int v[707] = {};
init(n);
for (int i=1; i<=n; i++) {
for (int j=0; j<graph[i].size(); j++) {
if(graph[i][j].second < p || graph[i][j].second > q){
if (find(i) != find(graph[i][j].first)) {
uni(i,graph[i][j].first);
v[find(graph[i][j].first)] = 1;
}
}
}
}
memset(v,0,sizeof(v));
int r = 0;
for (int i=1; i<=n; i++) {
if(v[find(i)] == 0){
v[find(i)] = 1;
r++;
}
}
printf("%d\n",r);
}
int main(){
int x,y,q;
scanf("%d %d",&n,&m);
for (int i=0; i<m; i++) {
scanf("%d %d",&x,&y);
if(x>y) swap(x,y);
graph[x].push_back(pi(y,i+1));
}
scanf("%d",&q);
for (int i=0; i<q; i++) {
scanf("%d %d",&x,&y);
query(x,y);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1300 KB |
Output is correct |
2 |
Correct |
0 ms |
1300 KB |
Output is correct |
3 |
Correct |
0 ms |
1300 KB |
Output is correct |
4 |
Correct |
0 ms |
1300 KB |
Output is correct |
5 |
Correct |
0 ms |
1300 KB |
Output is correct |
6 |
Correct |
0 ms |
1300 KB |
Output is correct |
7 |
Correct |
0 ms |
1300 KB |
Output is correct |
8 |
Correct |
0 ms |
1300 KB |
Output is correct |
9 |
Correct |
0 ms |
1300 KB |
Output is correct |
10 |
Correct |
0 ms |
1300 KB |
Output is correct |
11 |
Correct |
0 ms |
1300 KB |
Output is correct |
12 |
Correct |
4 ms |
1300 KB |
Output is correct |
13 |
Correct |
0 ms |
1300 KB |
Output is correct |
14 |
Correct |
0 ms |
1300 KB |
Output is correct |
15 |
Correct |
0 ms |
1300 KB |
Output is correct |
16 |
Correct |
0 ms |
1300 KB |
Output is correct |
17 |
Correct |
0 ms |
1300 KB |
Output is correct |
18 |
Correct |
0 ms |
1300 KB |
Output is correct |
19 |
Correct |
0 ms |
1300 KB |
Output is correct |
20 |
Correct |
0 ms |
1300 KB |
Output is correct |
21 |
Correct |
0 ms |
1300 KB |
Output is correct |
22 |
Correct |
0 ms |
1300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
1432 KB |
Output is correct |
2 |
Correct |
420 ms |
1432 KB |
Output is correct |
3 |
Correct |
452 ms |
1432 KB |
Output is correct |
4 |
Correct |
1104 ms |
1828 KB |
Output is correct |
5 |
Correct |
1104 ms |
1828 KB |
Output is correct |
6 |
Execution timed out |
2500 ms |
1828 KB |
Program timed out |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2500 ms |
1960 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |