-
Notifications
You must be signed in to change notification settings - Fork 10
/
Learning Graph -HackerEarth
56 lines (48 loc) · 1.12 KB
/
Learning Graph -HackerEarth
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
// Just Think about Corner Cases That When The Same Values Will be appeared then , according to indices U have to arrange those same values in ascending order .
// I used here a vector pair and a custom function
#include<bits/stdc++.h>
using namespace std;
bool myfunc(pair<int,int> &a,pair<int,int> &b)
{
if(a.second==b.second)
return a.first>b.first;
return a.second>b.second;
}
int main()
{
int n,m1,k,val,u,v;
cin>>n>>m1>>k;
vector<int>adj[n+1];
map<int,int>m;
map<int,int>va;
int count=1;
for(int j=1;j<=n;j++)
{
cin>>val;
m[j]=val;
va[val]=j;
}
while(m1--)
{
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++)
{
vector<pair<int,int> > vec;
if(adj[i].size()<k)
{
cout<<"-1"<<endl;
}
else{
for(int f=0;f<adj[i].size();f++)
{
vec.push_back(make_pair(adj[i][f],m[adj[i][f]]));
}
sort(vec.begin(),vec.end(),myfunc);
cout<<vec[k-1].first<<endl;
}
}
return 0;
}