-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcom.cpp
executable file
·56 lines (51 loc) · 1.33 KB
/
concom.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
/*
ID: paulius10
PROG: concom
LANG: C++
*/
#include <fstream>
#define MAX_COMPANIES 101
using namespace std;
void update(int first[][MAX_COMPANIES], int second[][MAX_COMPANIES],
bool controlled[][MAX_COMPANIES], int i, int j) {
if (controlled[i][j] || i == j) return;
controlled[i][j] = true;
for (int k = 0; k < MAX_COMPANIES; k++) {
second[i][k] += first[j][k];
if (first[i][k] + second[i][k] > 50) update(first, second, controlled, i, k);
}
}
int main() {
int first[MAX_COMPANIES][MAX_COMPANIES];
int second[MAX_COMPANIES][MAX_COMPANIES];
bool controlled[MAX_COMPANIES][MAX_COMPANIES];
for (int i = 0; i < MAX_COMPANIES; i++) {
for (int j = 0; j < MAX_COMPANIES; j++) {
first[i][j] = 0;
second[i][j] = 0;
controlled[i][j] = false;
}
}
ifstream fin("concom.in");
int n;
fin >> n;
for (int x = 0; x < n; x++) {
int i, j;
fin >> i >> j;
fin >> first[i][j];
}
fin.close();
for (int i = 0; i < MAX_COMPANIES; i++) {
for (int j = 0; j < MAX_COMPANIES; j++) {
if (first[i][j] > 50) update(first, second, controlled, i, j);
}
}
ofstream fout("concom.out");
for (int i = 0; i < MAX_COMPANIES; i++) {
for (int j = 0; j < MAX_COMPANIES; j++) {
if (controlled[i][j]) fout << i << ' ' << j << endl;
}
}
fout.close();
return 0;
}