Submission #765401

#TimeUsernameProblemLanguageResultExecution timeMemory
765401vjudge1Network (BOI15_net)C++17
100 / 100
998 ms84680 KiB
/****************** tree-bends-in-youth //24///06///2023/// ******************/ #include <bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() using namespace std; const ll N = 1e6 + 1; const ll INF = 1e17; const ll MOD = 1e9 + 7; vector<int>g[N]; vector <int> l; map<int,int>used; int tm; void dfs(int v){ used[v]=1; if(g[v].size() == 1)l.pb(v); for(ll to : g[v]){ if(!used[to]){ dfs(to); } } } void solve(){ int n; cin >> n; for(int i=1;i<n;i++){ int x,y; cin>>x>>y; g[x].pb(y); g[y].pb(x); } int r = 0; for(int i = 1;i <= n;i++){ if(g[i].size() > 1){ r = i; break; } } dfs(r); int k = (l.size() + 1) / 2; cout << k << '\n'; for(int i = 0;i + k < l.size();i++){ cout << l[i] << " " << l[i + k] << '\n'; } if(l.size() % 2){ cout << l[0] << " " << l[k - 1] << '\n'; } } main () { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("censor.in","r",stdin); //freopen("censor.out","w",stdout); ll T = 1; //cin >> T; for(ll i = 1;i <= T;i++){ // cout << "Case " << i << ":\n"; solve(); } }

Compilation message (stderr)

net.cpp: In function 'void solve()':
net.cpp:47:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0;i + k < l.size();i++){
      |                   ~~~~~~^~~~~~~~~~
net.cpp: At global scope:
net.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...