-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTask O.cpp
More file actions
58 lines (50 loc) · 1.06 KB
/
Task O.cpp
File metadata and controls
58 lines (50 loc) · 1.06 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool dfs (int i, vector <vector <int>> ¶, int *trade, bool start = true){
trade[i] = !start;
bool answer;
for (auto p : para[i]){
if (trade[p] == -1){
answer = dfs(p, para, trade, !start);
} else if (trade[i] == trade[p]){
return false;
}
}
return answer;
}
void solve(){
int n, m;
cin >> n >> m;
bool answer;
vector <vector <int>> para (n);
int trade[n];
memset(trade, -1, sizeof(trade));
while (m != 0){
int p1, p2;
cin >> p1 >> p2;
para[--p1].push_back(--p2);
para[p2].push_back(p1);
m--;
}
int i = 0;
while (n != 0){
if (trade[i] == -1){
answer = dfs(i, para, trade);
}
i++;
n--;
}
if (answer){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}