problem statement is here
#include<stdio.h>
int main(){
int t,i,j,f,p,q;
scanf("%d",&t);
while(t--){
int n,m;
f=0;
scanf("%d%d",&n,&m);
if(m==0)
printf("2 %d\n",n);
else{
int ar[n];
for(i=0;i<=n-1;i++)
ar[i]=i;
for(i=0;i<=m-1;i++){
scanf("%d%d",&p,&q);
ar[p-1]+=1;
ar[q-1]-=1;
}
for(i=n-1;i>=0;i--){
if(ar[i]==n-1){
j=i;
f=1;
break;
}
}
if(f==1)
printf("2 %d\n",j+1);
else
printf("1\n");
}
}
return 0;
}
No comments:
Post a Comment