-
Notifications
You must be signed in to change notification settings - Fork 1
/
irevir.cpp
82 lines (67 loc) · 1.25 KB
/
irevir.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
typedef vector < vector <int> > Graph;
int main(void)
{
int N, M;
int V, W, P;
while (1) {
inicio:
scanf ("%d", &N);
if (!N) break;
scanf("%d", &M);
Graph g1(N+1);
Graph g2(N+1);
for (int i = 0; i < M; i++) {
scanf ("%d %d %d", &V, &W, &P);
g1[V].push_back(W);
g2[W].push_back(V);
if (P == 2) {
g1[W].push_back(V);
g2[V].push_back(W);
}
}
int visited[N+1];
queue<int> Q;
memset(visited, 0, sizeof(visited));
Q.push(1);
while (!Q.empty()) {
int e = Q.front();
Q.pop();
printf ("Trata %d\n", e);
if (!visited[e]) {
visited[e]++;
for (int i = 0; i < g1[e].size(); i++)
Q.push(g1[e][i]);
}
}
for (int i = 1; i <= N; i++)
if (visited[i] == 0) {
printf ("indo %d = 0\n", i);
goto inicio;
}
memset(visited, 0, sizeof(visited));
Q.push(1);
visited[1] = 1;
while (!Q.empty()) {
int e = Q.front();
Q.pop();
if (!visited[e]) {
visited[e]++;
for (int i = 0; i < g2[e].size(); i++)
Q.push(g2[e][i]);
}
}
for (int i = 1; i <= N; i++)
if (visited[i] == 0) {
printf ("0\n");
goto inicio;
}
printf ("1\n");
}
return 0;
}