# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
609294 | 2022-07-27T13:24:07 Z | sword060 | Network (BOI15_net) | C++17 | 7 ms | 11988 KB |
#include <bits/stdc++.h> using namespace std; int x; vector<int>v[500005]; vector<pair<int,int>>ans; vector<int> dfs(int i,int p=-1){ vector<int>ret; if(v[i].size()==1)ret.push_back(i); for(auto j:v[i]){ if(j==p)continue; vector<int>lol=dfs(j,i); for(auto k:lol)ret.push_back(k); } if(i==1){ for(int j=0;j<ret.size()/2;j++) ans.push_back({ret[j],ret[ret.size()-j-1]}); if((int)ret.size()%2)ans.push_back({ret[ret.size()/2],ret.back()}); } return ret; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>x; for(int i=1;i<=x-1;i++){ int l,r;cin>>l>>r; v[l].push_back(r); v[r].push_back(l); } dfs(1); cout<<ans.size()<<"\n"; for(auto [l,r]:ans)cout<<l<<" "<<r<<endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11988 KB | Output is correct |
2 | Incorrect | 7 ms | 11988 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11988 KB | Output is correct |
2 | Incorrect | 7 ms | 11988 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11988 KB | Output is correct |
2 | Incorrect | 7 ms | 11988 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |