This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 d=pq.top().first;
int u=pq.top().second;
if(dist[u]!=d) continue;
pq.pop();
for(int i=0;i<graph[u].size();i++)
{
int v=graph[u][i].first, w=graph[u][i].second;
if(dist[v]< min(dist[u],w))
{
dist[v]=min(dist[u],w);
pq.push(ii(dist[v],v));
}
}
}
while(q--)
{
int x;
cin >> x;
cout << dist[x] << endl;
}
return 0;
}
Compilation message (stderr)
cats.cpp: In function 'int main()':
cats.cpp:30: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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |