# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893451 | 2023-12-27T05:04:31 Z | vjudge1 | Meetings 2 (JOI21_meetings2) | C++17 | 100 ms | 1360 KB |
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() //#define sz size() #define vll vector<ll> #define bc back() #define arr array using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <class _T> bool chmin(_T &x, const _T &y){ bool flag=false; if(x>y) {x=y;flag|=true;} return flag; } template <class _T> bool chmax(_T &x, const _T &y){ bool flag=false; if (x<y) {x=y;flag|=true;} return flag; } #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=1e9+7; const ll mod=1e9+7; const ll N=4e3+5; const ld eps=1e-9; vector<vll> g(N),g2(N); ll d[N],sz[N],p[N]; ll n; ll tin[N],tout[N]; void dfs_sz(ll v){ sz[v]=1; for(auto i : g[v]){ if(i==p[v]) continue; d[i]=d[v]+1; p[i]=v; dfs_sz(i); sz[v]+=sz[i]; } } ll find_cen(ll v){ for(auto i : g[v]){ if(d[v]>d[i]) continue; if(sz[i]>n/2){ return find_cen(i); } } return v; } ll d2[N]; void dfs(ll v){ for(auto i : g2[v]){ if(d2[i]<d2[v]) continue; d2[i]=d2[v]+1; dfs(i); } } ll dia(ll r){ memset(d2,0x3f,sizeof(d2)); d2[r]=0; dfs(r); ll mx=0; for(ll i=1;i<=n;i++){ if(g2[i].size()){ if(chmax(mx,d2[i])){ r=i; } } } memset(d2,0x3f,sizeof(d2)); d2[r]=0; dfs(r); mx=0; for(ll i=1;i<=n;i++){ if(g2[i].size()){ chmax(mx,d2[i]); } } return mx; } void solve(){ ll i,j; ll a,b; cin>>n; for(i=1;i<n;i++){ cin>>a>>b; g[a].pb(b); g[b].pb(a); } dfs_sz(1); ll r=find_cen(1); d[r]=1; memset(p,0,sizeof(p)); dfs_sz(r); vector<vll> v(n+5); for(i=1;i<=n;i++){ v[sz[i]].pb(i); } ll ans[n+5]; ll mx=0,mx2=0; for(i=n/2;i>0;i--){ for(auto j : v[i]){ g2[j].pb(p[j]); g2[p[j]].pb(j); } if(g2[r].size()==0){ ans[i*2]=1; }else{ ans[i*2]=dia(r)+1; } } for(i=1;i<=n;i++){ if(i%2) cout<<1<<endl; else cout<<ans[i]<<endl; } } signed main(){ start(); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 0 ms | 604 KB | Output is correct |
6 | Correct | 0 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 604 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 600 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 0 ms | 604 KB | Output is correct |
12 | Correct | 0 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 604 KB | Output is correct |
14 | Correct | 0 ms | 604 KB | Output is correct |
15 | Correct | 0 ms | 604 KB | Output is correct |
16 | Correct | 0 ms | 856 KB | Output is correct |
17 | Correct | 1 ms | 604 KB | Output is correct |
18 | Correct | 1 ms | 604 KB | Output is correct |
19 | Correct | 0 ms | 604 KB | Output is correct |
20 | Correct | 0 ms | 604 KB | Output is correct |
21 | Correct | 1 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 0 ms | 604 KB | Output is correct |
6 | Correct | 0 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 604 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 600 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 0 ms | 604 KB | Output is correct |
12 | Correct | 0 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 604 KB | Output is correct |
14 | Correct | 0 ms | 604 KB | Output is correct |
15 | Correct | 0 ms | 604 KB | Output is correct |
16 | Correct | 0 ms | 856 KB | Output is correct |
17 | Correct | 1 ms | 604 KB | Output is correct |
18 | Correct | 1 ms | 604 KB | Output is correct |
19 | Correct | 0 ms | 604 KB | Output is correct |
20 | Correct | 0 ms | 604 KB | Output is correct |
21 | Correct | 1 ms | 604 KB | Output is correct |
22 | Correct | 13 ms | 1116 KB | Output is correct |
23 | Correct | 12 ms | 1116 KB | Output is correct |
24 | Correct | 14 ms | 1116 KB | Output is correct |
25 | Correct | 14 ms | 1132 KB | Output is correct |
26 | Correct | 12 ms | 1136 KB | Output is correct |
27 | Correct | 8 ms | 1116 KB | Output is correct |
28 | Correct | 15 ms | 1116 KB | Output is correct |
29 | Correct | 11 ms | 1116 KB | Output is correct |
30 | Correct | 14 ms | 1136 KB | Output is correct |
31 | Correct | 10 ms | 1276 KB | Output is correct |
32 | Correct | 76 ms | 1256 KB | Output is correct |
33 | Correct | 100 ms | 1360 KB | Output is correct |
34 | Correct | 2 ms | 1112 KB | Output is correct |
35 | Correct | 2 ms | 1116 KB | Output is correct |
36 | Correct | 19 ms | 1148 KB | Output is correct |
37 | Correct | 14 ms | 1116 KB | Output is correct |
38 | Correct | 41 ms | 1112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 0 ms | 604 KB | Output is correct |
6 | Correct | 0 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 604 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 600 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 0 ms | 604 KB | Output is correct |
12 | Correct | 0 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 604 KB | Output is correct |
14 | Correct | 0 ms | 604 KB | Output is correct |
15 | Correct | 0 ms | 604 KB | Output is correct |
16 | Correct | 0 ms | 856 KB | Output is correct |
17 | Correct | 1 ms | 604 KB | Output is correct |
18 | Correct | 1 ms | 604 KB | Output is correct |
19 | Correct | 0 ms | 604 KB | Output is correct |
20 | Correct | 0 ms | 604 KB | Output is correct |
21 | Correct | 1 ms | 604 KB | Output is correct |
22 | Correct | 13 ms | 1116 KB | Output is correct |
23 | Correct | 12 ms | 1116 KB | Output is correct |
24 | Correct | 14 ms | 1116 KB | Output is correct |
25 | Correct | 14 ms | 1132 KB | Output is correct |
26 | Correct | 12 ms | 1136 KB | Output is correct |
27 | Correct | 8 ms | 1116 KB | Output is correct |
28 | Correct | 15 ms | 1116 KB | Output is correct |
29 | Correct | 11 ms | 1116 KB | Output is correct |
30 | Correct | 14 ms | 1136 KB | Output is correct |
31 | Correct | 10 ms | 1276 KB | Output is correct |
32 | Correct | 76 ms | 1256 KB | Output is correct |
33 | Correct | 100 ms | 1360 KB | Output is correct |
34 | Correct | 2 ms | 1112 KB | Output is correct |
35 | Correct | 2 ms | 1116 KB | Output is correct |
36 | Correct | 19 ms | 1148 KB | Output is correct |
37 | Correct | 14 ms | 1116 KB | Output is correct |
38 | Correct | 41 ms | 1112 KB | Output is correct |
39 | Runtime error | 1 ms | 856 KB | Execution killed with signal 11 |
40 | Halted | 0 ms | 0 KB | - |