-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph2.java
More file actions
67 lines (58 loc) · 1.46 KB
/
Copy pathGraph2.java
File metadata and controls
67 lines (58 loc) · 1.46 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
package dummy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Graph2 {
static boolean visited[];
static int val[];
static ArrayList<Node> al[];
static Scanner sc;
public static void main(String[] args) {
// TODO Auto-generated method stub
sc=new Scanner(System.in);
int N=sc.nextInt(), M=sc.nextInt(), K=sc.nextInt();
val= new int[N+1];
for(int i=1; i<=N; i++) val[i]=sc.nextInt();
al=new ArrayList[N+1];
for(int i=0; i<M; i++) {
int x=sc.nextInt();
int y=sc.nextInt();
if(al[x]==null)
al[x]=new ArrayList<Node>();
if(al[y]==null)
al[y]=new ArrayList<Node>();
if(x!=y) {
al[x].add(new Node(val[y], y));
al[y].add(new Node(val[x], x));
} else {
al[x].add(new Node(val[y], y));
}
}
for(int i=1; i<=N; i++) {
if(al[i]!=null) {
Collections.sort(al[i]);
if(al[i].size()-K>=0)
System.out.println((al[i].get(K-1)).index);
else
System.out.println(-1);
} else
System.out.println(-1);
}
}
}
class Node implements Comparable<Node>{
Integer val;
Integer index;
public Node(int val, int index){
this.val=val;
this.index=index;
}
@Override
public int compareTo(Node node) {
// TODO Auto-generated method stub
if(this.val!=node.val)
return node.val.compareTo(this.val);
else
return node.index.compareTo(this.index);
}
}