-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZombieMarch***.java
More file actions
83 lines (75 loc) · 2.55 KB
/
Copy pathZombieMarch***.java
File metadata and controls
83 lines (75 loc) · 2.55 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Enter your code here. Read input from STDIN. Print output to STDOUT
Your class should be named Solution
*/
import java.util.*;
class Junction{
int id;
double zombieCount;
HashSet<Integer> edges;
Junction (int id) {
this.id = id;
this.edges = new HashSet<Integer>();
}
}
class SortByZomieCount implements Comparator<Junction>{
@Override
public int compare(Junction arg0, Junction arg1) {
if (arg0.zombieCount < arg1.zombieCount) {
return 1;
} else if (arg0.zombieCount > arg1.zombieCount) {
return -1;
} else {
return 0;
}
}
}
public class Solution {
static int TOP = 5;
public static void main (String args []) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int t = 0; t < T; t++) {
int N = in.nextInt();
int M = in.nextInt();
int k = in.nextInt();
Junction junctions [] = new Junction [N];
for (int i = 0; i < N; i++) {
junctions[i] = new Junction(i);
}
for (int i = 0; i < M; i++) {
int v1 = in.nextInt();
int v2 = in.nextInt();
junctions[v1].edges.add(v2);
junctions[v2].edges.add(v1);
}
for (int i = 0; i < N; i++) {
junctions[i].zombieCount = in.nextInt();
}
for (int i = 0; i < k; i++) {
float changes [] = new float [N];
Arrays.fill(changes, 0);
for (int j = 0; j < N; j++) {
Junction junction = junctions[j];
changes[j] -= junction.zombieCount;
HashSet<Integer> edges = junction.edges;
int edgesCount = edges.size();
for (int connectedJunctionId : edges) {
changes[connectedJunctionId] += junction.zombieCount / edgesCount;
}
}
for (int j = 0; j < N; j++) {
junctions[j].zombieCount += changes[j];
}
}
Arrays.sort(junctions, new SortByZomieCount());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < TOP - 1; i ++){
sb.append((int) Math.round(junctions[i].zombieCount));
sb.append(" ");
}
sb.append((int) Math.round(junctions[TOP -1].zombieCount));
System.out.println(sb.toString());
}
}
}