-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcom.java
More file actions
59 lines (51 loc) · 1.35 KB
/
Copy pathconcom.java
File metadata and controls
59 lines (51 loc) · 1.35 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
52
53
54
55
56
57
58
59
/*
ID: 001207j1
LANG: JAVA
TASK: concom
*/
import java.io.*;
import java.util.*;
public class concom {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
concom c = new concom();
c.run();
}
public static void run() throws IOException {
long start_Time = System.currentTimeMillis();
BufferedReader f = new BufferedReader(new FileReader("concom.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("concom.out")));
int n = Integer.parseInt(f.readLine());
int[][] st = new int[101][101];
boolean[][] c = new boolean[101][101];
Set<Integer> a = new HashSet<Integer>();
for (int i = 0; i < n; i++) {
String[] s = f.readLine().split(" ");
int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]), v = Integer.parseInt(s[2]);
a.add(x);
a.add(y);
st[x][y] = v;
}
for (int s : a) {
int[] ct = new int[101];
boolean[] flag= new boolean[101];
DFS(st, s, ct, flag, a);
for (int j : a)
if (ct[j] > 50)
out.println(s + " " + j);
}
f.close();
out.close();
System.out.println(System.currentTimeMillis() - start_Time);
}
public static void DFS(int[][] st, int s, int[] ct, boolean[] flag, Set<Integer> a) {
if(flag[s])
return;
flag[s] = true;
for (int j : a) {
ct[j] += st[s][j];
if (ct[j] > 50)
DFS(st, j, ct, flag, a);
}
}
}