#include <iostream>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main()
{
int n,m,q;
cin >> n >> m >> q;
vector< vector<ii> >graph;
graph.assign(n+1,vector<ii>());
for(int i=0;i<m;i++)
{
int u,v,w;
cin >> u >> v >> w;
graph[u].push_back(ii(v,w));
graph[v].push_back(ii(u,w));
}
priority_queue<ii , vector<ii> , greater<ii> > pq;
vector<int> dist (n+1,0);
dist[1]=2e9;
pq.push(ii(2e9,1));
while(!pq.empty())
{
int u=pq.top().second;
if(dist[u]!=pq.top().first) continue;
pq.pop();
for(int i=0;i<graph[u].size();i++)
{
if(dist[graph[u][i].first]< min(dist[u],graph[u][i].second))
{
dist[graph[u][i].first]=min(dist[u],graph[u][i].second);
pq.push(ii(dist[graph[u][i].first],graph[u][i].first));
}
}
}
for(int i=0;i<q;i++)
{
int x;
cin >> x;
cout << dist[x] << endl;
}
return 0;
}
Compilation message
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<graph[u].size();i++)
~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
436 KB |
Output is correct |
2 |
Correct |
10 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3541 ms |
3308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3541 ms |
65112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |