-
Notifications
You must be signed in to change notification settings - Fork 2
/
closing.cpp
45 lines (43 loc) · 1.1 KB
/
closing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("closing.in", "r", stdin);
freopen("closing.out", "w", stdout);
int N, M;
cin >> N >> M;
vector<int> edges[3000];
for(int i = 0; i < M; i++){
int a, b;
cin >> a >> b;
edges[a-1].push_back(b-1);
edges[b-1].push_back(a-1);
}
unordered_set<int> closed;
for(int i = 0; i < N; i++){
stack<int> dfs;
int start = 0;
for(; closed.find(start) != closed.end(); start++){}
dfs.push(start);
unordered_set<int> been;
while(!dfs.empty()){
int idx = dfs.top();
dfs.pop();
if(been.find(idx) != been.end() || closed.find(idx) != closed.end()){
continue;
}
been.insert(idx);
for(int j : edges[idx]){
dfs.push(j);
}
}
if(been.size() == N - i){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
int rm;
cin >> rm;
closed.insert(rm - 1);
}
return 0;
}