-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudy_10282.java
More file actions
64 lines (60 loc) · 1.35 KB
/
Study_10282.java
File metadata and controls
64 lines (60 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
60
61
62
63
64
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
// Create by Inho 2018. 5. 2.
public class Study_10282{
static class node{
int a,s;
node(int a, int s){
this.a = a;
this.s = s;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int TC = sc.nextInt();
while(TC-->0) {
int N = sc.nextInt()+1;
int D = sc.nextInt();
int C = sc.nextInt();
int[] sum = new int[N];
boolean[] state = new boolean[N];
ArrayList<node>[] map = new ArrayList[N];
for(int i=0;i<N;i++){
map[i] = new ArrayList<node>();
sum[i] = 987654321;
}
for(int i=0;i<D;i++){
int a =sc.nextInt();
int b = sc.nextInt();
int s = sc.nextInt();
map[b].add(new node(a,s));
}
PriorityQueue<Integer> q = new PriorityQueue<>();
q.add(C);
sum[C] =0;
while(!q.isEmpty()){
int node = q.poll();
state[node] = true;
for(int i=0;i<map[node].size();i++){
int next = map[node].get(i).a;
if( sum[next] > sum[node] + map[node].get(i).s){
sum[next] = sum[node] + map[node].get(i).s;
q.add(next);
}
}
}
int count =0;
int max = 0;
for(int i=0;i<N;i++){
if(state[i] != false){
count++;
}
if(sum[i] != 987654321 && max < sum[i]){
max = sum[i];
}
}
System.out.println(count + " " + max);
}
}
}