#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
5396 KB |
Output is correct |
2 |
Correct |
106 ms |
4560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3529 ms |
124044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |