# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
804406 | 2023-08-03T08:33:18 Z | vjudge1 | Meetings 2 (JOI21_meetings2) | C++17 | 1 ms | 980 KB |
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 1e4 + 9 , mod = 1e9 + 7; ll d[N] = {} , a[N] = {}, dp[N] = {}, b[N] , c[N] , us[N] = {} , us1[N] = {} , p[N][20] , sz[N] = {} , root , timer = 0; vector<int>v[N] ; set<ll>st[N]; bool is_upper(int x , int y){ return (us[x] <= us[y] && us1[x] >= us1[y]); } ll lca(int x , int y){ if(is_upper(x , y)) return x; if(is_upper(y , x)) return y; for(int i = 19; i >= 0; i--) if(p[x][i] && !is_upper(p[x][i] , y)) x = p[x][i] ; return p[x][0]; } ll dist(int x , int y){ return (d[x] + d[y] - (2 * d[lca(x ,y)])); } void dfs(int n ){ us[n] = ++timer; for(int i = 1; i < 20; i++) p[n][i] = p[p[n][i - 1]][i - 1]; for(auto to : v[n]) if(us[to] == 0) d[to] = d[n] + 1, p[to][0] = n , dfs(to); us1[n] = ++timer; } void solve(){ ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n; for(i = 1; i < n; i++){ cin>>l>>r; v[l].pb(r); v[r].pb(l); st[l].insert(r); st[r].insert(l); } for(i = 1; i <= n; i++) if(v[i].size() == 1) root = i; dfs(1); set<pair<int,int>> s1 , s2; for(i = 1; i <= n; i++){ b[i] = 1; if(st[i].size() == 1) s1.insert({b[i] , i}); } while(s1.size()){ auto it = s1.begin(); k = it->se; s2.insert({b[k] , k}); s1.erase(it); if(st[k].size() == 1){ x = *st[k].begin(); s2.insert({b[k] , k}); st[x].erase(k); st[k].erase(x); b[x] += b[k]; s2.insert({b[x] , x}); if(st[x].size() == 1) s1.insert({b[x] , x}); } } /*for(auto it : s2){ cout<<it.fi<<" "<<it.se<<"\n"; }*/ for(i = n; i >= 1; i--){ if(i % 2 == 1){ c[i] = 1; }else { mx = 0; vector<int>v; while(s2.size() && s2.rbegin()->fi >= (i / 2)) v.pb(s2.rbegin()->se) , s2.erase({s2.rbegin()->fi , s2.rbegin()->se}); for(x= 0;x < v.size();x++) for(y = x + 1; y < v.size(); y++) mx = max(mx , dist(v[x] , v[y]) + 1); c[i] = max(c[i + 2] , mx); } } for(i = 1; i <= n; i++) cout<<c[i]<<"\n"; } int main(){ TL; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Correct | 1 ms | 980 KB | Output is correct |
3 | Correct | 1 ms | 980 KB | Output is correct |
4 | Correct | 1 ms | 980 KB | Output is correct |
5 | Correct | 1 ms | 980 KB | Output is correct |
6 | Incorrect | 1 ms | 980 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Correct | 1 ms | 980 KB | Output is correct |
3 | Correct | 1 ms | 980 KB | Output is correct |
4 | Correct | 1 ms | 980 KB | Output is correct |
5 | Correct | 1 ms | 980 KB | Output is correct |
6 | Incorrect | 1 ms | 980 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 980 KB | Output is correct |
2 | Correct | 1 ms | 980 KB | Output is correct |
3 | Correct | 1 ms | 980 KB | Output is correct |
4 | Correct | 1 ms | 980 KB | Output is correct |
5 | Correct | 1 ms | 980 KB | Output is correct |
6 | Incorrect | 1 ms | 980 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |