#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 100010;
const int MAXM = 500010;
struct Edge
{
int v, next;
}edge[MAXM];
int n, m, s;
int cnt;
int first[MAXN];
bool color[MAXN], vis[MAXN];
void init()
{
cnt = 0;
memset(vis, 0, sizeof(vis));
memset(color, 0, sizeof(color));
memset(first, -1, sizeof(first));
}
void read_graph(int u, int v)
{
edge[cnt].v = v;
edge[cnt].next = first[u], first[u] = cnt++;
}
int find(int u)
{
for(int e = first[u]; e != -1; e = edge[e].next)
{
int v = edge[e].v;
if(!vis[v])
{
vis[v] = 1;
color[v] = !color[u];
find(v);
}
else if(color[u] == color[v]) return false;
}
return true;
}
int main()
{
int T, times = 0;
scanf("%d", &T);
while(T--)
{
init();
scanf("%d%d%d", &n, &m, &s);
while(m--)
{
int u, v;
scanf("%d%d", &u, &v);
read_graph(u, v);
read_graph(v, u);
}
printf("Case %d: ", ++times);
color[s] = 1;
vis[s] = 1;
printf(find(s)?"NO\n":"YES\n");
}
return 0;
}
05-20
05-20
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交