# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
32312 | 2017-10-08T14:12:45 Z | dqhungdl | Network (BOI15_net) | C++14 | 6 ms | 14384 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; int n; bool Free[500005]; vector<int> V,g[500005]; vector<ii> rs; void DFS(int u) { Free[u]=true; if(g[u].size()==1) { V.push_back(u); return; } for(int i=0;i<g[u].size();i++) if(Free[g[u][i]]==false) DFS(g[u][i]); } int main() { ios_base::sync_with_stdio(false); //freopen("NET.INP","r",stdin); cin>>n; int u,v; for(int i=1;i<n;i++) { cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } for(int i=1;i<=n;i++) if(g[i].size()>=2) { DFS(i); break; } cout<<(V.size()+1)/2<<"\n"; for(int i=0;i<=(V.size()-1)/2;i++) cout<<V[i]<<' '<<V[i+V.size()/2]<<"\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 14384 KB | Output is correct |
2 | Correct | 3 ms | 14384 KB | Output is correct |
3 | Correct | 0 ms | 14384 KB | Output is correct |
4 | Correct | 3 ms | 14384 KB | Output is correct |
5 | Correct | 3 ms | 14384 KB | Output is correct |
6 | Correct | 6 ms | 14384 KB | Output is correct |
7 | Correct | 6 ms | 14384 KB | Output is correct |
8 | Correct | 0 ms | 14384 KB | Output is correct |
9 | Correct | 0 ms | 14384 KB | Output is correct |
10 | Correct | 3 ms | 14384 KB | Output is correct |
11 | Correct | 3 ms | 14384 KB | Output is correct |
12 | Correct | 0 ms | 14384 KB | Output is correct |
13 | Correct | 6 ms | 14384 KB | Output is correct |
14 | Correct | 0 ms | 14384 KB | Output is correct |
15 | Correct | 3 ms | 14384 KB | Output is correct |
16 | Correct | 6 ms | 14384 KB | Output is correct |
17 | Correct | 3 ms | 14384 KB | Output is correct |
18 | Correct | 0 ms | 14384 KB | Output is correct |
19 | Correct | 3 ms | 14384 KB | Output is correct |
20 | Correct | 0 ms | 14384 KB | Output is correct |