Submission #667189

#TimeUsernameProblemLanguageResultExecution timeMemory
667189ktkeremNetwork (BOI15_net)C++17
0 / 100
23 ms32212 KiB
/*#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/ #include<bits/stdc++.h> /**/ //typedef int ll; typedef long long ll; typedef unsigned long long ull; typedef std::string str; //typedef vector<std::vector<ll>> vv; /*typedef __int128 vll; typedef unsigned __int128 uvll;*/ #define llll std::pair<ll , ll> #define pb push_back #define pf push_front #define halo cout << "hello\n" #define fi first #define sec second #define vv(x) std::vector<std::vector<x>> #define all(a) a.begin() , a.end() const ll limit = 1e9+7; const ll ous = 5e5 + 7; const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1}; template <typename T> std::string type_name(); ll n , m;std::vector<ll> ar; std::vector<ll> adj[ous] , lc(ous) , v; ll cnt = 0; ll finlevcnt(ll crt , ll prv = 0 , ll crp = 0){ for(auto j:adj[crt]){ if(j != prv){ ll o = finlevcnt(j , crt , lc[crt] - lc[j] + crp); if(o){ return o; } } } if(adj[crt].size() < 2){ return 0; } ll kd = (cnt + 1)/2 >= crp; for(auto j:adj[crt]){ if(kd == 0){ break; } if(j != prv){ if(lc[j] >=(cnt + 1)/2){ kd =0; } } } return(kd ?crt :0); } ll dfs(ll crt , ll prv){ ll k = 1; for(auto j:adj[crt]){ if(j != prv){ k = 0; lc[crt] += dfs(j , crt); } } if(k || adj[crt].size() < 2){ lc[crt] += 1; cnt++; } return lc[crt]; } void fndlv(ll crt , ll prv){ if(adj[crt].size() < 2){ v.pb(crt); return; } for(auto j:adj[crt]){ if(j != prv){ fndlv(j , crt); } } } void solve(){ ll n;std::cin >> n; for(ll i = 0;n-1>i;i++){ ll x , y;std::cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } dfs(1 , 0); ll o = finlevcnt(1); for(auto j:adj[o]){ fndlv(j , o); } ll tl = 0; ll ps = (cnt + 1) / 2 * 2; ll ans [ps]; for(ll i = 0;ps>i;i++){ ans[tl] = v[i % v.size()]; tl+=2; if(tl == ps){ tl = 1; } } std::cout << ps / 2 << "\n"; for(ll i = 0;ps>i;i+=2){ std::cout << ans[i] << " " << ans[i+1] << "\n"; } return;/**/ } signed main(){ std::ios_base::sync_with_stdio(false);std::cin.tie(NULL); ll t=1; //std::cin >> t; ll o = 1; while(t--){ //cout << "Case " << o++ << ":\n"; solve(); } return 0; }/**/

Compilation message (stderr)

net.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
net.cpp: In function 'int main()':
net.cpp:112:8: warning: unused variable 'o' [-Wunused-variable]
  112 |     ll o = 1;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...