-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI075.java
More file actions
46 lines (41 loc) · 1.58 KB
/
I075.java
File metadata and controls
46 lines (41 loc) · 1.58 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
package levelB;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class I075 {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str=br.readLine().split(" ");
int first=Integer.parseInt(str[0]);
int N=Integer.parseInt(str[1]);
int K=Integer.parseInt(str[2]);
int[] next=new int[100000];
int[] data=new int[100000];
for(int i=0;i<N;i++){
str=br.readLine().split(" ");
next[Integer.parseInt(str[0])]=Integer.parseInt(str[2]);
data[Integer.parseInt(str[0])]=Integer.parseInt(str[1]);
}
br.close();
ArrayList<Integer> list_fu=new ArrayList<>();
ArrayList<Integer> list_ling=new ArrayList<>();
ArrayList<Integer> list_K=new ArrayList<>();
while(first!=-1){
if(data[first]<0)
list_fu.add(first);
else if(data[first]>K)
list_K.add(first);
else
list_ling.add(first);
first=next[first];
}
ArrayList<Integer> list=new ArrayList<>();
list.addAll(list_fu);
list.addAll(list_ling);
list.addAll(list_K);
for(int i=0;i<list.size()-1;i++){
System.out.printf("%05d %d %05d\n",list.get(i),data[list.get(i)],list.get(i+1));
}
System.out.printf("%05d %d -1\n",list.get(list.size()-1),data[list.get(list.size()-1)]);
}
}