Submission #102147

#TimeUsernameProblemLanguageResultExecution timeMemory
102147Leonardo_PaesNetwork (BOI15_net)C++11
100 / 100
718 ms41064 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 100; int v[MAXN], cnt; vector<int> grafo[MAXN]; void dfs(int u, int p) { for (int i=0; i<grafo[u].size(); i++){ int v = grafo[u][i]; if (v == p) continue; dfs(v, u); } if (grafo[u].size() == 1) v[++cnt] = u; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); int n; cin >> n; for(int i=1; i<n; i++){ int a, b; cin >> a >> b; grafo[a].push_back(b); grafo[b].push_back(a); } for(int i=1; i<=n; i++){ if(grafo[i].size()>1){ dfs(i, 0); break; } } int ans = (cnt+1)/2; cout << ans << "\n"; for(int i=1; i<ans; i++){ cout << v[i] << " " << v[i+ans] << "\n"; } if(cnt&1){ cout << v[ans] << " " << v[1] << "\n"; } else{ cout << v[ans] << " " << v[cnt]; } return 0; }

Compilation message (stderr)

net.cpp: In function 'void dfs(int, int)':
net.cpp:13:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<grafo[u].size(); i++){
                ~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...