#include <bits/stdc++.h>
#define rpd ios_base :: sync_with_stdio(0); cin.tie(0);
#define ll long long
#define fs first
#define sc second
#define pb push_back
#define mod int(1e9)+7
#define NMAX 500000 + 5
#define inf INT_MAX
using namespace std;
ifstream in(".in");
ofstream out(".out");
set<pair<int,int> >s;
vector<pair<int, int> > g[NMAX];
int dist[NMAX];
void dij(){
s.insert({1,-10000000});
while(s.size()){
auto st= *(s.begin());
int mini= -(st.sc);
int nod= st.fs;
s.erase(s.begin());
for(auto x:g[nod])
{
int vecin= x.fs;
int cost= -(x.sc);
if(min(cost,mini)>dist[vecin]){
s.erase({vecin,-dist[vecin]});
dist[vecin]=min(cost,mini);
s.insert({vecin,-dist[vecin]});
}
}
}
}
int main()
{
rpd;
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=m;i++)
{
int a,b,c;
cin>>a>>b>>c;
g[a].pb({b,-c});
g[b].pb({a,-c});
}
for(int i=1;i<=n;++i)
{ dist[i] = 0;
sort(g[i].begin() , g[i].end());
}
dij();
while(q--)
{
int x;
cin>>x;
cout<<dist[x]<<'\n';
}
return 0;
}
/*
4 4 2
1 2 10
1 3 30
2 4 20
3 4 5
3
4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11980 KB |
Output is correct |
2 |
Correct |
8 ms |
11992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12196 KB |
Output is correct |
2 |
Correct |
9 ms |
12108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
14368 KB |
Output is correct |
2 |
Correct |
82 ms |
13892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3566 ms |
98416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |