#include <bits/stdc++.h>
using namespace std;
const int nx=5e5+5;
int n, m, q, u, v, w, dsu[nx], dp[nx];
vector<tuple<int, int, int>> ed;
vector<pair<int, int>> d[nx];
void dfs(int u, int p)
{
for (auto [v, w]:d[u]) if (v!=p) dp[v]=min(dp[u], w), dfs(v, u);
}
int find(int x)
{
if (dsu[x]==x) return x;
return dsu[x]=find(dsu[x]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>q;
for (int i=0; i<m; i++) cin>>u>>v>>w, ed.push_back({w, u, v});
sort(ed.begin(), ed.end());
reverse(ed.begin(), ed.end());
for (int i=1; i<=n; i++) dsu[i]=i;
for (auto [w, u, v]:ed) if (find(u)!=find(v)) dsu[find(u)]=find(v), d[u].push_back({v, w}), d[v].push_back({u, w});
dp[1]=INT_MAX;
dfs(1, 1);
while (q--) cin>>u, cout<<dp[u]<<'\n';
}
/*
4 4 2
1 2 10
1 3 30
2 4 20
3 4 5
3
4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15012 KB |
Output is correct |
2 |
Correct |
3 ms |
15016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
17812 KB |
Output is correct |
2 |
Correct |
20 ms |
17360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1128 ms |
125040 KB |
Output is correct |
2 |
Correct |
1769 ms |
201268 KB |
Output is correct |