View Code of Problem 131

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

//思路:不存在环,如果存在环则a到b,b到a都存在 
int main(){
	int map[110][110];
	int a,b;
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF){
		for(int i=1;i<=109;i++){
			for(int j=1;j<=109;j++){
				map[i][j]=0;
			}
		} 
		for(int i=1;i<=m;i++){
			scanf("%d %d",&a,&b);
			map[b][a]=1;
		}
		for(int i=1;i<=n;i++){//以i为中心,j到k是否存在 
			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