-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStarNight.cpp
More file actions
62 lines (50 loc) · 1007 Bytes
/
StarNight.cpp
File metadata and controls
62 lines (50 loc) · 1007 Bytes
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
#include "bits/stdc++.h"
#ifdef LOCAL
#include "F:\CPP\Debug\debug.h"
#else
#define print(...) 1;
#endif
using i64 = long long;
void solve()
{
int n, m;
std::cin >> n >> m;
std::vector<int> adj[n];
for (int i = 0; i < m; i++)
{
int u, v;
std::cin >> u >> v;
u--, v--;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
int bad = 0;
std::vector<int> c(n, -1);
std::function<void(int, int)> dfs = [&](int u, int col)
{
c[u] = col;
for (int v : adj[u])
{
if (c[v] == -1)
dfs(v, 1 - col);
else if (c[v] == col)
bad = 1;
}
};
for (int i = 0; i < n; i++)
{
if (c[i] == -1)
dfs(i, 0);
}
std::cout << (bad ? "NO\n" : "YES\n");
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--)
solve();
return 0;
}