제출 #24940

#제출 시각아이디문제언어결과실행 시간메모리
24940RezwanArefin01Network (BOI15_net)C++14
0 / 100
3 ms13744 KiB
//Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; const int maxn = 500100; vector<int> adj[maxn], lef; void dfs(int u, int par){ int cnt = 0; for(int v : adj[u]) if(v - par){ cnt++, dfs(v, u); } if(!cnt) lef.push_back(u); } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif int n; cin>>n; for(int i=0; i<n-1; i++) { int u, v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1, 0); vector<int> a = lef; lef.clear(); dfs(2, 0); vector<int> b = lef; sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector<int> c; merge(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c)); c.erase(unique(c.begin(), c.end()), c.end()); if(c.size() == 1) { cout<<1<<endl; cout<<c[0]<<" " << 1<<endl; return 0; } cout<<(int) (c.size() + 1)/2<<endl; for(int i=0; i+1<c.size(); i+=2) { cout<<c[i]<<" " << c[i+1]<<endl; } if(c.size() & 1) { cout << c[0] << " " << c[c.size()-1]<<endl; } }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main(int, const char**)':
net.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i+1<c.size(); i+=2) {
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...