forked from lshtar13/PS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1707.cc
65 lines (55 loc) · 1.07 KB
/
1707.cc
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
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string solve(void)
{
int v,e;
scanf("%d %d", &v, &e);
vector<int> mat(v, 0);
vector<vector<int>> edges(v);
for(int i = 0, a, b; i<e; ++i)
{
scanf("%d %d", &a, &b);
edges[a-1].push_back(b-1);
edges[b-1].push_back(a-1);
}
queue<int> q;
for(int i = 0; i<v; ++i)
{
if(mat[i])
{
continue;
}
q.push(i);
mat[i] = 1;
while(q.size())
{
int vertex = q.front();
q.pop();
for(auto av: edges[vertex])
{
if(mat[av] == mat[vertex])
{
return "NO";
}
if(mat[av])
{
continue;
}
mat[av] = -mat[vertex];
q.push(av);
}
}
}
return "YES";
}
int main(void)
{
int k;
scanf("%d", &k);
while(k--)
{
cout<<solve()<<endl;
}
return 0;
}