View Code of Problem 131

#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int n, m,a,b;
	while (scanf("%d%d", &n, &m) != EOF) {
		int s[100][100] = {};
		for (int i = 0; i < m; i++) {
			scanf("%d %d", &a, &b);
			s[b][a] = 1;
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					if (s[i][k] && s[k][j]) {
						s[i][j] = 1;
					}
				}
			}
		}
		int flag = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				if (s[i][j] && s[j][i]) {
					flag = 0;
					break;
				}
			}
		}
		if (flag) {
			printf("RIGHT\n");
		}
		else {
			printf("ERROR\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 131