Submission #659214

#TimeUsernameProblemLanguageResultExecution timeMemory
659214zaneyuMeetings 2 (JOI21_meetings2)C++14
0 / 100
3 ms5044 KiB
/*input 7 1 2 2 3 3 4 4 5 2 6 3 7 */ #include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace __gnu_pbds; typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; //order_of_key #of elements less than x // find_by_order kth element using ll=long long; using ld=long double; using pii=pair<ll,ll>; #define f first #define s second #define pb push_back #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET(v,x) lower_bound(ALL(v),x)-v.begin() const int maxn=2e5+5; const ll INF=0x3f3f3f3f; const ld PI=acos(-1.0l); const ld eps=1e-6; const ll INF64=4e18+1; const int MOD=1e9+7; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<P.f<<' '<<P.s; return out; } template<typename T> ostream& operator<<(ostream& out,vector<T> V){ REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?"\n":""); return out; } inline ll mult(ll a,ll b){ return a*b%MOD; } ll mypow(ll a,ll b){ if(b<=0) return 1; ll res=1LL; while(b){ if(b&1) res=mult(res,a); a=mult(a,a); b>>=1; } return res; } vector<int> v[maxn]; int d[maxn],pos[maxn]; void dfs(int u,int p){ for(int x:v[u]){ if(x==p) continue; d[x]=d[u]+1; dfs(x,u); } } int t,c; vector<int> pth; bool on[maxn]; bool get(int u,int p){ if(u==t){ return true; } for(int x:v[u]){ if(x==p) continue; if(get(x,u)){ pth.pb(x); return 1; } } return 0; } void mrk(int u,int p){ pos[u]=c; for(int x:v[u]){ if(on[x] or x==p) continue; mrk(x,u); } } int main(){ ios::sync_with_stdio(false),cin.tie(0); int n; cin>>n; REP(i,n-1){ int a,b; cin>>a>>b; --a,--b; v[a].pb(b),v[b].pb(a); } dfs(0,-1); int p=max_element(d,d+n)-d; d[p]=0; dfs(p,-1); int pp=max_element(d,d+n)-d; t=pp; get(p,-1); pth.pb(p); for(int x:pth) on[x]=1; REP(i,sz(pth)){ c=i; mrk(pth[i],-1); } vector<int> v; REP(i,n){ v.pb(pos[i]); } sort(ALL(v)); REP1(i,n){ if(i%2) cout<<1<<'\n'; else cout<<v[sz(v)-i/2]-v[i/2-1]+1<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...