# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
170400 | banterbry | 관광 (NOI14_sightseeing) | C++17 | 3122 ms | 122136 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |