답안 #1008385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008385 2024-06-26T10:30:08 Z Unforgettablepl Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 23036 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> adj(n+1);
    for(int i=1;i<n;i++){
        int a,b;cin>>a>>b;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }
    int centroid = -1;
    function<int(int,int)> find_centroid = [&](int x,int p){
        int siz = 1;
        for(int&i:adj[x])if(i!=p)siz+=find_centroid(i,x);
        if(n-siz<=n/2 and siz<=n){
            centroid = x;
            return (int)1e15;
        }
        return siz;
    };
    find_centroid(1,0);
    vector<int> depths;
    vector<int> subsize;
    function<int(int,int,int)> dfs = [&](int x,int p,int depth){
        int siz = 1;
        vector<int> idx = {(int)depths.size()};
        depths.emplace_back(depth);
        subsize.emplace_back(0);
        for(int&i:adj[x])if(i!=p){
            siz+=dfs(i,x,depth+1);
            idx.emplace_back(depths.size());
            depths.emplace_back(depth);
            subsize.emplace_back(0);
        }
        for(int&i:idx)subsize[i]=siz;
        return siz;
    };
    dfs(centroid,0,1);
    vector<int> ans(n+1);
    for(int i=0;i<depths.size();i++){
        int mindep = depths[i];
        for(int j=i+1;j<depths.size();j++){
            mindep = min(mindep,depths[j]);
            ans[min(subsize[i],subsize[j])]=max(ans[min(subsize[i],subsize[j])],depths[i]+depths[j]-2ll*mindep+1ll);
        }
    }
    for(int i=n-1;i;i--)ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;i++){
        if(i&1)cout<<"1\n";
        else cout<<ans[i/2]<<'\n';
    }
}

Compilation message

meetings2.cpp: In function 'int32_t main()':
meetings2.cpp:47:18: 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]
   47 |     for(int i=0;i<depths.size();i++){
      |                 ~^~~~~~~~~~~~~~
meetings2.cpp:49:24: 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]
   49 |         for(int j=i+1;j<depths.size();j++){
      |                       ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 54 ms 860 KB Output is correct
23 Correct 57 ms 860 KB Output is correct
24 Correct 52 ms 1036 KB Output is correct
25 Correct 53 ms 860 KB Output is correct
26 Correct 53 ms 860 KB Output is correct
27 Correct 58 ms 856 KB Output is correct
28 Correct 54 ms 856 KB Output is correct
29 Correct 56 ms 860 KB Output is correct
30 Correct 55 ms 860 KB Output is correct
31 Correct 56 ms 900 KB Output is correct
32 Correct 55 ms 856 KB Output is correct
33 Correct 43 ms 1112 KB Output is correct
34 Correct 53 ms 1196 KB Output is correct
35 Correct 51 ms 856 KB Output is correct
36 Correct 57 ms 860 KB Output is correct
37 Correct 50 ms 856 KB Output is correct
38 Correct 47 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 54 ms 860 KB Output is correct
23 Correct 57 ms 860 KB Output is correct
24 Correct 52 ms 1036 KB Output is correct
25 Correct 53 ms 860 KB Output is correct
26 Correct 53 ms 860 KB Output is correct
27 Correct 58 ms 856 KB Output is correct
28 Correct 54 ms 856 KB Output is correct
29 Correct 56 ms 860 KB Output is correct
30 Correct 55 ms 860 KB Output is correct
31 Correct 56 ms 900 KB Output is correct
32 Correct 55 ms 856 KB Output is correct
33 Correct 43 ms 1112 KB Output is correct
34 Correct 53 ms 1196 KB Output is correct
35 Correct 51 ms 856 KB Output is correct
36 Correct 57 ms 860 KB Output is correct
37 Correct 50 ms 856 KB Output is correct
38 Correct 47 ms 856 KB Output is correct
39 Execution timed out 4033 ms 23036 KB Time limit exceeded
40 Halted 0 ms 0 KB -