Submission #101921
Source Code Expand
#include<iostream> #include<vector> #include<map> #include<algorithm> using namespace std; int N,E,K; const int MAX_N = 100000; int par[MAX_N]; int rank[MAX_N]; typedef pair<int,int>P; struct Edge{ int from,to; bool used; }; void init(){ for(int i = 0 ; i < N ; i++){ par[i] = i; rank[i] = 0; } } int find(int x){ if(par[x] == x){ return x; }else { return par[x] = find(par[x]); } } void unite(int x,int y){ x = find(x); y = find(y); if(x == y)return; if(rank[x] < rank[y]){ par[x] = y; } else { par[y] = x; if(rank[x] == rank[y])rank[x]++; } } bool same(int x,int y){ return find(x) == find(y); } int main(){ cin >> N >> E >> K; vector<Edge>edges; for(int i = 0 ; i < E ; i++){ Edge e; cin >> e.from >> e.to; e.from--; e.to--; e.used = false; edges.push_back(e); } vector<P>vec; for(int i = 0 ; i < K ; i++){ P p; int a; cin >> a; if(a){ cin >> p.first >> p.second; p.first--; p.second--; } else { cin >> p.first; p.first--; edges[p.first].used = true; p.second = -1; } vec.push_back(p); } init(); for(int i = 0 ; i < E ; i++){ if(!edges[i].used){ //cout << edges[i].from+1 << ' ' << edges[i].to+1 << endl; unite(edges[i].from,edges[i].to); } } /* for(int i = 0 ; i < N ; i++){ cout << "i = " << i+1 << " find : " << find(i) << endl; } */ vector<int>res; for(int i = K-1 ; i >= 0 ; i--){ if(vec[i].second == -1){ int id = vec[i].first; unite(edges[id].from,edges[id].to); } else { res.push_back(same(vec[i].first,vec[i].second)); /* cout << vec[i].first+1 << ' ' << vec[i].second+1 << endl;// cout << find(vec[i].first)+1 << ' ' << find(vec[i].second)+1 << endl;// cout << same(vec[i].first,vec[i].second) << endl; cout << endl; */ } } reverse(res.begin(),res.end()); for(int i = 0 ; i < res.size() ; i++){ cout << (res[i]?"YES":"NO") << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Graph Destruction |
User | aizu_b |
Language | C++ (GCC 4.4.7) |
Score | 100 |
Code Size | 2190 Byte |
Status | AC |
Exec Time | 525 ms |
Memory | 4764 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 4, 5, 50, 6, 7, 8, 9 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
1 | AC | 21 ms | 924 KB |
10 | AC | 30 ms | 804 KB |
11 | AC | 68 ms | 1056 KB |
12 | AC | 163 ms | 1504 KB |
13 | AC | 303 ms | 2200 KB |
14 | AC | 447 ms | 2964 KB |
15 | AC | 484 ms | 3744 KB |
16 | AC | 525 ms | 4764 KB |
17 | AC | 167 ms | 1816 KB |
18 | AC | 152 ms | 1752 KB |
19 | AC | 193 ms | 1820 KB |
2 | AC | 20 ms | 796 KB |
20 | AC | 371 ms | 2452 KB |
21 | AC | 192 ms | 1780 KB |
22 | AC | 268 ms | 2328 KB |
23 | AC | 203 ms | 1828 KB |
24 | AC | 141 ms | 1424 KB |
25 | AC | 157 ms | 1568 KB |
26 | AC | 395 ms | 3096 KB |
27 | AC | 131 ms | 1512 KB |
28 | AC | 144 ms | 1512 KB |
29 | AC | 311 ms | 2456 KB |
3 | AC | 22 ms | 732 KB |
30 | AC | 228 ms | 2080 KB |
31 | AC | 390 ms | 2840 KB |
32 | AC | 302 ms | 2452 KB |
33 | AC | 330 ms | 2672 KB |
34 | AC | 390 ms | 3100 KB |
35 | AC | 358 ms | 2724 KB |
36 | AC | 176 ms | 1692 KB |
4 | AC | 21 ms | 928 KB |
5 | AC | 21 ms | 804 KB |
50 | AC | 391 ms | 2828 KB |
6 | AC | 21 ms | 800 KB |
7 | AC | 23 ms | 804 KB |
8 | AC | 25 ms | 924 KB |
9 | AC | 27 ms | 808 KB |