Submission #524743

#TimeUsernameProblemLanguageResultExecution timeMemory
524743perchutsNetwork (BOI15_net)C++17
18 / 100
8 ms12108 KiB
#include <bits/stdc++.h> #define maxn (int)(1e5+51) #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define ll long long #define pb push_back #define ull unsigned long long #define ii pair<int,int> #define iii tuple<int,int,int> #define inf 2000000001 #define mod 1000000007 //998244353 #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } vector<int>g[5*maxn]; vector<int>leaves; void dfs(int x,int p){ int ok = 0; for(auto v:g[x]){ if(v==p)continue; ok = 1; dfs(v,x); } if(!ok||(x==1&&sz(g[x])==1))leaves.pb(x); } int main(){_ int n;cin>>n; for(int i=1;i<n;i++){ int a,b;cin>>a>>b; g[a].pb(b); g[b].pb(a); } dfs(1,1); int x = sz(leaves); cout<<(x+1)/2<<endl; for(int i=0;i<x/2;i++)cout<<leaves[i]<<" "<<leaves[i+x/2]<<endl; if(x&1){ int u = leaves[x-1],v; for(int i=1;i<=n;i++)if(i!=u&&i!=g[u][0])v=i; cout<<u<<" "<<v<<endl; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:5:14: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
    5 | #define endl '\n'
      |              ^~~~
net.cpp:42:29: note: 'v' was declared here
   42 |         int u = leaves[x-1],v;
      |                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...