# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170400 | banterbry | Sightseeing (NOI14_sightseeing) | C++17 | 3122 ms | 122136 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int,int> pi;
const int MAXE = 5000005, MAXN = 500005;
int N,E,Q,p[MAXN],ans[MAXN];
vector<pi> adj[MAXN];
struct edge {
int u,v,c;
} edgelist[MAXE];
bool cmp(edge a, edge b) {return a.c > b.c;}
struct ufds_ {
ufds_() {
for (int i = 1; i <= N; i++) p[i] = i;
}
int find(int x) {
if (p[x] == x) return x;
return p[x] = find(p[x]);
}
void merge(int x, int y) {
x = find(x); y = find(y);
p[x] = y;
}
} ufds;
void dfs(int x, int par, int w) {
ans[x] = w;
for (auto it: adj[x]) {
if (it.first == par) continue;
dfs(it.first,x,min(w,it.second));
}
}
int main() {
scanf("%d%d%d",&N,&E,&Q);
for (int i = 0; i < E; i++) {
scanf("%d%d%d",&edgelist[i].u,&edgelist[i].v,&edgelist[i].c);
}
sort(edgelist,edgelist+E,cmp);
ufds_();
for (int i = 0; i < E; i++) {
int u = edgelist[i].u, v = edgelist[i].v, c = edgelist[i].c;
if (ufds.find(u) == ufds.find(v)) continue;
ufds.merge(u,v);
adj[u].pb(mp(v,c));
adj[v].pb(mp(u,c));
}
dfs(1,-1,1e9+7);
while (Q--) {
int x; scanf("%d",&x);
printf("%d\n",ans[x]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |