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 <vector>
#include <iostream>
#include <queue>
#define int int64_t
using namespace std;
signed main()
{
int v, e, q;
cin >> v >> e >> q;
vector<vector<pair<int,int>>> adjlist(v);
for (int z = 0; z < e; z++)
{
int st, en, qu;
cin >> st >> en >> qu;
st--; en--;
adjlist[st].push_back({en, qu});
adjlist[en].push_back({st, qu});
}
vector<int> visited(v, -1);
visited[0] = 1e12;
priority_queue<pair<int,int>> pq;
pq.push({0, 0});
while (!pq.empty())
{
int curr = pq.top().second;
pq.pop();
for (auto p : adjlist[curr])
{
int next = p.first;
int quality = min(visited[curr], p.second);
if (quality > visited[next])
{
visited[next] = quality;
pq.push({quality, next});
}
}
}
for (int i = 0; i < q; i++)
{
int n;
cin >> n;
n--;
cout << visited[n] << "\n";
}
}
# | 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... |