View Code of Problem 131

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

 
int main(){

	int a,b;
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF){
		int map[200][200] = {0};
		for(int i=1;i<=m;i++){
			scanf("%d %d",&a,&b);
			map[b][a]=1;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					if(map[j][k]>0){
						continue;
					}else{
						if(map[j][i]>0&&map[i][k]>0){
							map[j][k]=1;
						}
					}
				}
			}
		}
		int flag=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(map[i][j]==1&&map[j][i]==1){
					flag=1;
					break;
				}
			}
		}
		if(flag==1){
			printf("ERROR\n");
		}else{
			printf("RIGHT\n");
		}
	}
}



	

Double click to view unformatted code.


Back to problem 131