-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11581.cpp
More file actions
51 lines (38 loc) · 1.01 KB
/
11581.cpp
File metadata and controls
51 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include <string>
using namespace std;
const int INF = 123456789;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N;
cin >> N;
int arr[101][101];
fill(&arr[0][0], &arr[100][101], INF);
for (int i = 1; i <= N - 1; i++) {
int C; cin >> C;
for (int j = 0; j < C; j++) {
int temp; cin >> temp;
arr[i][temp] = 1;
}
}
for (int k = 1; k <= N; k++) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (arr[i][j] > arr[i][k] + arr[k][j]) {
arr[i][j] = arr[i][k] + arr[k][j];
}
}
}
}
for (int i = 1; i <= N; i++) {
if (arr[1][i]!=INF && arr[i][i] != INF) {
cout << "CYCLE";
return 0;
}
}
cout << "NO CYCLE";
}