#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 5e5 + 69;
int sz[maxn];
int root[maxn];
vector <int> st[maxn];
int ans[maxn];
int findroot(int x)
{
while (x!=root[x])
x = root[x];
return x;
}
void unite(int x, int y)
{
if (x==y)
return;
if (sz[x]<sz[y])
swap(x, y);
sz[x] += sz[y];
root[y] = x;
for (int i=0; i<(int)(st[y].size()); i++)
st[x].push_back(st[y][i]);
st[y].clear();
}
void Solve()
{
int v, e, q;
cin>>v>>e>>q;
vector <pair<int, pair<int, int>>> edg;
for (int i=0; i<e; i++)
{
int a, b, c;
cin>>a>>b>>c;
a--;
b--;
edg.push_back(make_pair(c, make_pair(a, b)));
}
sort(edg.begin(), edg.end(), greater<pair<int, pair<int, int>>>());
for (int i=0; i<v; i++)
{
sz[i] = 1;
root[i] = i;
st[i].push_back(i);
}
for (int i=0; i<e; i++)
{
int u = edg[i].second.first;
int v = edg[i].second.second;
u = findroot(u);
v = findroot(v);
int w = findroot(0);
if (v==w)
{
swap(u, v);
}
if (u==w && v!=w)
{
//cout<<"YES "<<i+1<<" "<<v+1<<"\n";
for (int j=0; j<(int)(st[v].size()); j++)
{
//cout<<"UPDATED "<<st[v][j] + 1<<" "<<edg[i].first<<"\n";
ans[st[v][j]] = edg[i].first;
}
}
unite(u, v);
}
for (int i=0; i<q; i++)
{
int x;
cin>>x;
x--;
cout<<ans[x]<<"\n";
}
}
int32_t main()
{
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12260 KB |
Output is correct |
2 |
Correct |
6 ms |
12084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
16364 KB |
Output is correct |
2 |
Correct |
26 ms |
15996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1456 ms |
114612 KB |
Output is correct |
2 |
Correct |
2118 ms |
262144 KB |
Output is correct |