# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
24512 | Bruteforceman | Network (BOI15_net) | C++11 | 3 ms | 15696 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
int deg[500010];
deque <int> nodes;
vector <int> g[500010];
void dfs(int x, int par) {
if(deg[x] == 1) {
nodes.push_back(x);
}
for(auto i : g[x]) {
if(i - par) {
dfs(i, x);
}
}
}
int main(int argc, char const *argv[])
{
int n;
scanf("%d", &n);
for(int i = 1; i < n; i++) {
int p, q;
scanf("%d %d", &p, &q);
++deg[p];
++deg[q];
g[p].push_back(q);
g[q].push_back(p);
}
for(int i = 1; i <= n; i++) {
if(deg[i] != 1) {
dfs(i, 0);
break;
}
}
printf("%d\n", (nodes.size() + 1) >> 1);
int good = nodes.front();
while(nodes.size() > 1) {
int p = nodes.front();
int q = nodes.back();
nodes.pop_front();
nodes.pop_back();
printf("%d %d\n", p, q);
}
if(!nodes.empty()) {
printf("%d %d\n", good, nodes.front());
}
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... |