#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;
int v, e, q;
vector<pair<int,int>> edge[500050];
int ans[500050];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false); //int tests; cin >> tests; while (tests--)
{
cin >> v >> e >> q;
for (int i = 0; i < 500050; ++i)
edge[i].clear();
for (int i = 0; i < e; ++i)
{
int a, b, c;
cin >> a >> b >> c;
a--; b--;
edge[a].push_back({ c, b });
edge[b].push_back({ c, a });
}
priority_queue<pair<int, pair<int, int>>> pq;
for (auto e : edge[0])
{
pq.push({ e.first, { 0, e.second } });
}
memset(ans, -1, sizeof(ans));
ans[0] = 987654321;
while (!pq.empty())
{
auto e = pq.top(); pq.pop();
if (ans[e.second.second] == -1)
{
ans[e.second.second] = min(ans[e.second.first], e.first);
for (auto ee : edge[e.second.second])
{
if (ans[ee.second] == -1)
pq.push({ ee.first, { e.second.second, ee.second } });
}
}
}
for (int i = 0; i < q; ++i)
{
int x; cin >> x;
cout << ans[x - 1] << endl;
}
}}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
15388 KB |
Output is correct |
2 |
Correct |
6 ms |
15388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
15672 KB |
Output is correct |
2 |
Correct |
7 ms |
15520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
17812 KB |
Output is correct |
2 |
Correct |
151 ms |
17196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3279 ms |
0 KB |
SIGKILL Killed |
2 |
Halted |
0 ms |
0 KB |
- |