| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 46594 | alexpetrescu | Network (BOI15_net) | C++14 | 795 ms | 158208 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#define MAXN 500000
std::vector < int > g[MAXN + 1], v;
int s[MAXN + 1], cost[MAXN + 1];
bool viz[MAXN + 1], done[MAXN + 1];
void dfs(int x) {
s[x] = g[x].size() == 1;
viz[x] = 1;
for (auto &y : g[x]) {
if (viz[y] == 0) {
dfs(y);
s[x] += s[y];
cost[x] = std::max(cost[x], s[y]);
}
}
}
void dfs2(int x) {
if (g[x].size() == 1)
v.push_back(x);
done[x] = 1;
for (auto &y : g[x])
if (done[y] == 0)
dfs2(y);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1);
int ans = n + 1, r = 0;
for (int i = 1; i <= n; i++) {
if (g[i].size() != 1) {
int val = std::max(cost[i], s[1] - s[i]);
if (val < ans)
ans = val, r = i;
}
}
printf("%d\n", (s[1] + 1) / 2);
dfs2(r);
int k = v.size() / 2;
for (int i = 0; i < k; i++)
printf("%d %d\n", v[i], v[i + k]);
if (v.size() % 2)
printf("%d %d\n", v.back(), v[0]);
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... | ||||
