HDU-3478Catch二分图的否命题
题意:
考虑Thief能否;
由于我推着推着就想到必须要三点可以互通,和二分图的结论正好相反,所以就试了一发,
真没想到thief的初始位置是不用考虑的。
下面是ac代码:
#include <bits/stdc++.h> using namespace std; int n, m, s, book[100000 + 10]; vector<int> mp[100000 + 10]; bool dfs(int u) { queue<int> q; q.push(u); book[u] = 1; while (!q.empty()) { int from = q.front(); q.pop(); for (int i = 0; i < mp[from].size(); i++) { int tmp = mp[from][i]; if (book[tmp] == -1) { book[tmp] = !book[from]; q.push(tmp); } else if (book[tmp] == book[from]) return false; } } return true; } void init() { for (int i = 0; i < n; i++) mp[i].clear(); memset(book, -1, sizeof(book)); } int main() { int ca = 0, t; scanf("%d", &t); while (t--) { init(); scanf("%d%d%d", &n, &m, &s); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); mp[u].push_back(v); mp[v].push_back(u); } bool flag = false; for (int i = 0; i < n && !flag; i++) { if (book[i] == -1 && !dfs(i)) { flag = true; break; } } if (flag) printf("Case %d: YES\n", ++ca); else printf("Case %d: NO\n", ++ca); } return 0; }
skr