| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 516351 | Jomnoi | 관광 (NOI14_sightseeing) | C++17 | 2431 ms | 200676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int N = 5e5 + 10;
const int INF = 1e9 + 7;
vector <pair <int, int>> adj[N];
int parent[N];
int weight[N];
int ans[N];
int root(int u) {
if(u == parent[u]) {
return u;
}
return parent[u] = root(parent[u]);
}
void dfs(int u, int p) {
for(auto [v, w] : adj[u]) {
if(v == p) {
continue;
}
ans[v] = min(ans[u], w);
dfs(v, u);
}
}
int main() {
int n, m, q;
scanf(" %d %d %d", &n, &m, &q);
for(int i = 1; i <= n; i++) {
parent[i] = i;
}
vector <tuple <int, int, int>> edge;
while(m--) {
int u, v, w;
scanf(" %d %d %d", &u, &v, &w);
edge.emplace_back(w, u, v);
}
sort(edge.rbegin(), edge.rend());
for(auto [w, a, b] : edge) {
int u = root(a), v = root(b);
if(u == v) {
continue;
}
if(u > v) {
swap(u, v);
}
parent[v] = u;
adj[a].emplace_back(b, w);
adj[b].emplace_back(a, w);
}
ans[1] = INF;
dfs(1, -1);
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... | ||||
