Submission #1056068

# Submission time Handle Problem Language Result Execution time Memory
1056068 2024-08-13T07:34:56 Z 변재우(#11070) Summer Driving (CCO24_day1problem3) C++17
9 / 25
740 ms 44096 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=3010;
int N, R, A, B, dep[Nmax], par[Nmax], p, l[Nmax], r[Nmax], par2[12][Nmax];
int Da[Nmax][Nmax], Db[Nmax];
bool chka[Nmax][Nmax], chkb[Nmax];
vector<int> adj[Nmax];

void DFS(int curr, int prev) {
    l[curr]=++p;
    for(int next:adj[curr]) if(next!=prev) dep[next]=dep[curr]+1, par[next]=par2[0][next]=curr, DFS(next, curr);
    r[curr]=p;
}

int LCA(int u, int v) {
    if(dep[u]<dep[v]) swap(u, v);
    for(int i=11; i>=0; i--) if(dep[par2[i][u]]>dep[v]) u=par2[i][u];
    if(dep[u]!=dep[v]) u=par2[0][u];
    for(int i=11; i>=0; i--) if(par2[i][u]!=par2[i][v]) u=par2[i][u], v=par2[i][v];
    if(u!=v) u=par2[0][u];
    return u;
}
int Dist(int u, int v) {
    return dep[u]+dep[v]-2*dep[LCA(u, v)];
}

int F(int i, int j);
int G(int i);

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>R>>A>>B;
    if(A<=B) {
        cout<<1; return 0;
    }
    for(int i=1; i<N; i++) {
        int u, v; cin>>u>>v;
        adj[u].push_back(v), adj[v].push_back(u);
    }
    DFS(R, 0);
    for(int i=1; i<12; i++) for(int j=1; j<=N; j++) par2[i][j]=par2[i-1][par2[i-1][j]];
    cout<<F(R, 0);
    return 0;
}

int F(int i, int j) {
    if(chka[i][j]) return Da[i][j];
    chka[i][j]=true;
    bool flag=true;
    for(int k=1; k<=N; k++) if(dep[k]==dep[i]+A && l[i]<=l[k] && l[k]<=r[i] && !(l[j]<=l[k] && l[k]<=r[j]))
        Da[i][j]=max(Da[i][j], G(k)), flag=false;
    if(flag) {
        Da[i][j]=Nmax;
        for(int k=1; k<=N; k++) if(dep[k]<=dep[i]+B && l[i]<=l[k] && l[k]<=r[i] && !(l[j]<=l[k] && l[k]<=r[j]))
            Da[i][j]=min(Da[i][j], k);
    }
    return Da[i][j];
}

int G(int i) {
    if(chkb[i]) return Db[i];
    chkb[i]=true;
    bool chk[Nmax]={0};
    Db[i]=Nmax;
    for(int j=i; dep[i]-dep[j]<B; j=par[j]) Db[i]=min(Db[i], F(par[j], j)), chk[par[j]]=true;
    for(int j=1; j<=N; j++) if(Dist(i, j)<=B && !chk[j]) 
        Db[i]=min(Db[i], F(j, 0));
    return Db[i];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 161 ms 33716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2904 KB Output is correct
2 Correct 8 ms 2908 KB Output is correct
3 Correct 5 ms 2636 KB Output is correct
4 Correct 8 ms 3024 KB Output is correct
5 Correct 7 ms 2664 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 13 ms 2756 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 5 ms 2908 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2904 KB Output is correct
2 Correct 8 ms 2908 KB Output is correct
3 Correct 5 ms 2636 KB Output is correct
4 Correct 8 ms 3024 KB Output is correct
5 Correct 7 ms 2664 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 13 ms 2756 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 5 ms 2908 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 639 ms 41268 KB Output is correct
15 Correct 692 ms 31056 KB Output is correct
16 Correct 609 ms 29456 KB Output is correct
17 Correct 727 ms 31052 KB Output is correct
18 Correct 596 ms 29336 KB Output is correct
19 Correct 656 ms 32152 KB Output is correct
20 Correct 678 ms 30708 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 378 ms 22296 KB Output is correct
24 Correct 740 ms 32452 KB Output is correct
25 Correct 530 ms 44096 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 540 ms 21604 KB Output is correct
31 Correct 527 ms 21616 KB Output is correct
32 Correct 503 ms 21332 KB Output is correct
33 Correct 593 ms 29756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 12852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2904 KB Output is correct
2 Correct 8 ms 2908 KB Output is correct
3 Correct 5 ms 2636 KB Output is correct
4 Correct 8 ms 3024 KB Output is correct
5 Correct 7 ms 2664 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 13 ms 2756 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 5 ms 2908 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 639 ms 41268 KB Output is correct
15 Correct 692 ms 31056 KB Output is correct
16 Correct 609 ms 29456 KB Output is correct
17 Correct 727 ms 31052 KB Output is correct
18 Correct 596 ms 29336 KB Output is correct
19 Correct 656 ms 32152 KB Output is correct
20 Correct 678 ms 30708 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 378 ms 22296 KB Output is correct
24 Correct 740 ms 32452 KB Output is correct
25 Correct 530 ms 44096 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 540 ms 21604 KB Output is correct
31 Correct 527 ms 21616 KB Output is correct
32 Correct 503 ms 21332 KB Output is correct
33 Correct 593 ms 29756 KB Output is correct
34 Runtime error 21 ms 12824 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 Runtime error 161 ms 33716 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -