#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[500000];
int ans[500000];
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 < 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 |
15384 KB |
Output is correct |
2 |
Correct |
5 ms |
15384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
15668 KB |
Output is correct |
2 |
Correct |
5 ms |
15516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
17808 KB |
Output is correct |
2 |
Correct |
49 ms |
17192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3274 ms |
173052 KB |
SIGKILL Killed |
2 |
Halted |
0 ms |
0 KB |
- |