Posted on 2009-04-22 16:59
superman 阅读(82)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 freopen("concom.in", "r", stdin);
8 freopen("concom.out", "w", stdout);
9
10 int n;
11 int m[101][101] = { 0 };
12
13 cin >> n;
14 for (int i = 0; i < n; i++)
15 {
16 int a, b, c;
17 cin >> a >> b >> c;
18
19 m[a][b] = c;
20 }
21
22 bool control[101][101] = { false };
23
24 for (int p = 1; p <= 100; p++)
25 {
26 int x[101] = { 0 };
27 for (int i = 1; i <= 100; i++)
28 x[i] = m[p][i];
29
30 while (true)
31 {
32 int i;
33 for (i = 1; i <= 100; i++)
34 if (x[i] > 50 && control[p][i] == false)
35 {
36 control[p][i] = true;
37 for (int j = 1; j <= 100; j++)
38 x[j] += m[i][j];
39 break;
40 }
41 if (i > 100)
42 break;
43 }
44 }
45
46 for (int i = 1; i <= 100; i++)
47 for (int j = 1; j <= 100; j++)
48 if (control[i][j] && i != j)
49 cout << i << ' ' << j << endl;
50
51 return 0;
52 }
53