172. eXam
memory limit per test: 4096 KB
output: standard
One school does not want to warn teachers too much. They want to schedule all the exams into two days in such way that exams on some subjects are on the first day, and exams on all other (and only on them) are on second. You are to write a program, which will determine, if it is possible to schedule exams in this way so that all pupils will be able to do all their selected exams.
Input
Output
Sample test(s)
Input
2
1 4
#include <bits/stdc++.h>
using namespace std;
const int max_d=200+5;
const int max_b=30000*2+5;
bool f=1;
int dis[max_d][max_d];
int head[max_d];
int v[max_d];
int tot=1;
struct node{
int to;
int next;
};
node edge[max_b];
void add_edge(int x,int y){
edge[tot].to=y;
edge[tot].next=head[x];
head[x]=tot++;
edge[tot].to=x;
edge[tot].next=head[y];
head[y]=tot++;
}
void dfs(int x,int y){
v[x]=y;
for(int i=head[x];i!=0;i=edge[i].next){
if(v[edge[i].to]==y){
f=0;
return;
}
else if(v[edge[i].to]==0){
dfs(edge[i].to,-y);
}
}
}
void solve(){
int a,b;
scanf("%d%d",&a,&b);
for(int i=1;i<=b;i++){
int x,y;
scanf("%d%d",&x,&y);
if(dis[x][y]==1)continue;
dis[x][y]=1;
dis[y][x]=1;
add_edge(x,y);
}
for(int i=1;i<=a;i++){
if(v[i]==0){
dfs(i,1);
if(f==0){
printf("no");
return;
}
}
}
printf("yes\n");
int ans=0;
for(int i=1;i<=a;i++){
if(v[i]==1)ans++;
}
printf("%d\n",ans);
for(int i=1;i<=a;i++){
if(v[i]==1){
printf("%d ",i);
}
}
}
int main(){
solve();
return 0;
}