Submission #596476

# Submission time Handle Problem Language Result Execution time Memory
596476 2022-07-14T19:10:21 Z keta_tsimakuridze Meetings 2 (JOI21_meetings2) C++14
20 / 100
4000 ms 17728 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
#define Pii pair<pair<int,int> , pair<int,int> >
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t, sz[N], f[N], h;
int n, c;
int ans[N];
vector<pair<int, pair<int,int> > > x;
vector<int> V[N];
int find(int u,int p, int Sz) {
    for(int i = 0; i< V[u].size(); i++) {
        if(V[u][i] == p|| f[V[u][i]]) continue;
        if(sz[V[u][i]] > Sz / 2) return find(V[u][i], u, Sz);
    }
    return u;
}
void dfs(int u, int p) {
    sz[u] = 1;
    for(int i = 0; i < V[u].size(); i++) {
        if(V[u][i] == p || f[V[u][i]]) continue;
        dfs(V[u][i], u);
        sz[u] += sz[V[u][i]];
    }
}
void dfs(int u,int p,int P) {
    ++h;
    x.push_back({sz[u], {h, P}});
    ans[min(sz[u], n - sz[P]) * 2] = max(ans[min(sz[u], n - sz[P]) * 2], h + 1);
    for(int i = 0; i < V[u].size(); i++) {
        if(V[u][i] == p || f[V[u][i]]) continue;
        dfs(V[u][i], u, P);
    }
    --h;
}
void upd(Pii &mx, pii x) {
    if(x.s == mx.f.s) mx.f = max(mx.f, x);
    else  mx.s = max(mx.s, x);
    if(mx.f.f < mx.s.f) swap(mx.s, mx.f);
}
void decomp(int U) {
    dfs(U, 0);
    c = U;
    for(int i = 0; i < V[c].size(); i++) {
        if(f[V[c][i]] == 0) dfs(V[c][i], c, V[c][i]);
    }

    pair<pii, pii> mx;
    mx = {{-n, 0}, {-n, 0}};
    sort(x.begin(), x.end());
    while(x.size()) {
            int i = x.back().f;
            pii y = x.back().s;
            ans[i * 2] = max(ans[i * 2], y.f + (mx.f.s != y.s ? mx.f.f : mx.s.f ) + 1);
            upd(mx, y);
            x.pop_back();
    }
    return;
    f[c] = 1;
    for(int i = 0; i < V[c].size(); i++) {
        if(!f[V[c][i]])  decomp(V[c][i]);
    }
}
main(){
    cin >> n;
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        V[u].push_back(v);
        V[v].push_back(u);
    }
//    dfss(1, 0);
    for(int i = 1; i <= n; i++)
    decomp(i);
    for(int i = n; i >= 1; i--) {
        ans[i] = (i % 2 == 0 ? max(ans[i], ans[i + 2]) : 1);
    }
    for(int i = 1; i <= n; i++) {
        ans[i] = max(ans[i], 1);
        cout << ans[i] << "\n";
    }
 }

Compilation message

meetings2.cpp: In function 'int find(int, int, int)':
meetings2.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i< V[u].size(); i++) {
      |                    ~^~~~~~~~~~~~~
meetings2.cpp: In function 'void dfs(int, int)':
meetings2.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
meetings2.cpp: In function 'void dfs(int, int, int)':
meetings2.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
meetings2.cpp: In function 'void decomp(int)':
meetings2.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i = 0; i < V[c].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
meetings2.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < V[c].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
meetings2.cpp: At global scope:
meetings2.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 5008 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5012 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 5008 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5012 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5008 KB Output is correct
22 Correct 1686 ms 5308 KB Output is correct
23 Correct 1647 ms 5300 KB Output is correct
24 Correct 1630 ms 5300 KB Output is correct
25 Correct 1625 ms 5312 KB Output is correct
26 Correct 1629 ms 5300 KB Output is correct
27 Correct 1631 ms 5324 KB Output is correct
28 Correct 1641 ms 5312 KB Output is correct
29 Correct 1641 ms 5292 KB Output is correct
30 Correct 1655 ms 5204 KB Output is correct
31 Correct 1637 ms 5312 KB Output is correct
32 Correct 1396 ms 5528 KB Output is correct
33 Correct 1182 ms 5676 KB Output is correct
34 Correct 1238 ms 5296 KB Output is correct
35 Correct 689 ms 5304 KB Output is correct
36 Correct 1169 ms 5344 KB Output is correct
37 Correct 733 ms 5316 KB Output is correct
38 Correct 1063 ms 5488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 5008 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5012 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 5008 KB Output is correct
22 Correct 1686 ms 5308 KB Output is correct
23 Correct 1647 ms 5300 KB Output is correct
24 Correct 1630 ms 5300 KB Output is correct
25 Correct 1625 ms 5312 KB Output is correct
26 Correct 1629 ms 5300 KB Output is correct
27 Correct 1631 ms 5324 KB Output is correct
28 Correct 1641 ms 5312 KB Output is correct
29 Correct 1641 ms 5292 KB Output is correct
30 Correct 1655 ms 5204 KB Output is correct
31 Correct 1637 ms 5312 KB Output is correct
32 Correct 1396 ms 5528 KB Output is correct
33 Correct 1182 ms 5676 KB Output is correct
34 Correct 1238 ms 5296 KB Output is correct
35 Correct 689 ms 5304 KB Output is correct
36 Correct 1169 ms 5344 KB Output is correct
37 Correct 733 ms 5316 KB Output is correct
38 Correct 1063 ms 5488 KB Output is correct
39 Execution timed out 4088 ms 17728 KB Time limit exceeded
40 Halted 0 ms 0 KB -