#include <bits/stdc++.h>
#define f first
#define s second
#define N 500010
#define logn 20
using namespace std;
typedef pair<int, int> pii;
int n, m, q, pai[N], peso[N], nivel[N], ans[N];
vector<pii> grafo[N];
vector< pair<int, pii> > A;
int Find(int x)
{
if(x == pai[x]) return x;
return pai[x] = Find(pai[x]);
}
void join(int a, int b)
{
if(peso[a] >= peso[b]) swap(a, b);
pai[a] = b;
if(peso[a] == peso[b]) peso[b] ++;
}
void getans()
{
memset(ans, 0x3f3f3f3f, sizeof ans);
queue<pii> fila;
fila.push(pii(1, 1));
while(!fila.empty())
{
int x = fila.front().f, p = fila.front().s;
fila.pop();
for(auto v: grafo[x])
{
if(v.f == p) continue;
ans[v.f] = min(ans[x], v.s);
fila.push(pii(v.f, x));
}
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m>>q;
for(int i = 1, a, b, c; i <= m; i++)
{
cin>>a>>b>>c;
A.push_back(make_pair(c, pii(a, b)));
}
sort(A.rbegin(), A.rend());
for(int i = 1; i <= n; i++) pai[i] = i;
for(auto p: A)
{
int a = Find(p.s.f), b = Find(p.s.s);
if(a == b) continue;
join(a, b);
grafo[a].push_back(pii(b, p.f));
grafo[b].push_back(pii(a, p.f));
}
getans();
while(q--)
{
int x;
cin>>x;
cout<<ans[x]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
21712 KB |
Output is correct |
2 |
Correct |
0 ms |
21712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
21712 KB |
Output is correct |
2 |
Correct |
3 ms |
21712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
24020 KB |
Execution killed because of forbidden syscall writev (20) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1703 ms |
95480 KB |
Execution killed because of forbidden syscall writev (20) |
2 |
Halted |
0 ms |
0 KB |
- |