#include <bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind {
vector<int> p, ranks;
UnionFind(int n) : p(n), ranks(n, 0) {
for(int i = 0; i < n; ++i) {
p[i] = i;
}
}
int find_set(int a) {
return p[a] == a ? a : p[a] = find_set(p[a]);
}
bool is_same_set(int a, int b) {
return find_set(a) == find_set(b);
}
void unite(int a, int b) {
int x = find_set(a), y = find_set(b);
if(x != y) {
if(ranks[x] > ranks[y]) {
p[y] = x;
} else {
p[x] = y;
if(ranks[x] == ranks[y]) {
++ranks[y];
}
}
}
}
};
typedef pair<int, pair<int, int>> iii;
struct edge {
int v, w;
};
vector<vector<edge>> adj;
vector<int> dist;
void dfs(int u, int p = -1, int d = 1e9) {
dist[u] = d;
for(edge e : adj[u]) {
if(e.v != p) {
dfs(e.v, u, min(d, e.w));
}
}
}
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
int v, e, q;
cin >> v >> e >> q;
adj.resize(v);
dist.resize(v);
vector<iii> edges(e);
for(int i = 0; i < e; ++i) {
int a, b, c;
cin >> a >> b >> c;
--a; --b;
edges[i] = {c, {a, b}};
}
/*sort(edges.rbegin(), edges.rend());
UnionFind uf(v);
for(iii p : edges) {
int a = p.second.first, b = p.second.second;
int c = p.first;
if(!uf.is_same_set(a, b)) {
uf.unite(a, b);
adj[a].push_back(edge({b, c}));
adj[b].push_back(edge({a, c}));
}
}
dfs(0);*/
for(int i = 0; i < q; ++i) {
int x;
cin >> x;
--x;
cout << dist[x] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
2844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1088 ms |
83172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |