#include <bits/stdc++.h>
using namespace std;
struct edge{
int u, v, w;
bool operator< (const edge& o) {
return w < o.w;
}
};
struct qry{
int x, i;
bool operator< (const qry& o) {
return x < o.x;
}
};
const int MAXN = 5e5 + 11;
int ans[MAXN];
int dsu[MAXN]; vector<int> sons[MAXN];
void init(int n){
for(int i = 1; i <= n; i++) dsu[i] = i, sons[i].push_back(i);
}
int f(int x){
return x == dsu[x] ? x : dsu[x] = f(dsu[x]);
}
void g(int x, int y, int w){
x = f(x), y = f(y);
if(x == y) return;
if(f(1) == f(y)) swap(x, y);
if(f(1) == f(x)){
for(auto i : sons[y]){
ans[i] = w;
}
}else{
if(sons[x].size() < sons[y].size()) swap(x, y);
for(auto i : sons[y]){
sons[x].push_back(i);
}
}
sons[y].clear();
dsu[y] = x;
}
vector<edge> E[MAXN];
int main(){
int n, m, q; cin >> n >> m >> q;
for(int i = 0; i < m; i++){
int u, v, w; cin >> u >> v >> w;
E[w].push_back({u, v, w});
}
init(n);
for(int j = MAXN - 1; j >= 0; j--){
for(auto e : E[j]){
g(e.u, e.v, e.w);
}
}
for(int i = 0; i < q; i++){
int x; cin >> x; cout << ans[x] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23876 KB |
Output is correct |
2 |
Correct |
14 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
26700 KB |
Output is correct |
2 |
Correct |
60 ms |
26300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3234 ms |
94832 KB |
Output is correct |
2 |
Execution timed out |
3551 ms |
127228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |