Submission #434955

#TimeUsernameProblemLanguageResultExecution timeMemory
434955Blobo2_Blobo2Network (BOI15_net)C++17
0 / 100
1 ms204 KiB
/* Editor: Abdelrahman Hossam Nickname: Blobo2_Blobo2 IOI next year isA :) */ //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define all(v) v.begin(),v.end() #define gen(arr,n,nxt) generate(arr,arr+n,nxt) #define Blobo2_el_gamded_gedan_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0); const int mo=1e9+7; int nxt(){int x;cin>>x;return x;} signed main(){ Blobo2_el_gamded_gedan_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty int n=nxt(); vector<int>adj[n]; for(int i=0;i<n-1;i++){ int x=nxt()-1,y=nxt()-1; adj[x].push_back(y); adj[y].push_back(x); } vector<int>v; int cnt=0; for(int i=0;i<n;i++) if(adj[i].size()==1) cnt++,v.push_back(i); cout<<(cnt+1)/2<<endl; if(cnt%2==0){ for(int i=0;i<v.size();i+=2) cout<<v[i]+1<<' '<<v[i+1]+1<<endl; } else{ for(int i=0;i<v.size()-1;i+=2) cout<<v[i]+1<<' '<<v[i+1]+1<<endl; cout<<v.back()+1<<' '<<v[v.size()-2]+1<<endl; } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:35:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i=0;i<v.size();i+=2)
      |                     ~^~~~~~~~~
net.cpp:39:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i=0;i<v.size()-1;i+=2)
      |                     ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...