Submission #978201

# Submission time Handle Problem Language Result Execution time Memory
978201 2024-05-09T03:01:38 Z irmuun Swapping Cities (APIO20_swap) C++17
30 / 100
527 ms 524288 KB
#include<bits/stdc++.h>
#include "swap.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int N=1e5+5;

vector<int>cost(N,2e9);
vector<pair<int,int>>adj[N];
int par[N][20],P[N],dep[N],C[N][20];

void calc(int a,int b,int c){
    cost[a]=min(cost[a],max(cost[b],c));
    cost[b]=min(cost[b],max(cost[a],c));
}

void up(int x,int p){//direction
    P[x]=p;
    for(auto [y,w]:adj[x]){
        if(y!=p){
            C[y][0]=w;
            dep[y]=dep[x]+1;
            up(y,x);
            calc(x,y,w);
        }
    }
}
void down(int x,int p){
    for(auto [y,w]:adj[x]){
        if(y!=p){
            calc(x,y,w);
            down(y,x);
        }
    }
}

int find(int x,int d){
    for(int i=19;i>=0;i--){
        if(d&(1<<i)){
            x=par[x][i];
        }
    }
    return x;
}
int lca(int x,int y){
    if(dep[x]<dep[y]) swap(x,y);
    x=find(x,dep[x]-dep[y]);
    for(int i=19;i>=0;i--){
        if(par[x][i]!=par[y][i]){
            x=par[x][i];
            y=par[y][i];
        }
    }
    if(x==y) return x;
    return par[x][0];
}
int f(int x,int d){
    int res=0;
    for(int i=19;i>=0;i--){
        if(d&(1<<i)){
            res=max(res,C[x][i]);
            x=par[x][i];
        }
    }
    return res;
}

void init(int n,int m,vector<int>u,vector<int>v,vector<int>w){
    for(int i=0;i<n;i++){
        for(int j=0;j<20;j++){
            C[i][j]=2e9;
        }
    }
    for(int i=0;i<m;i++){
        adj[u[i]].pb({v[i],w[i]});
        adj[v[i]].pb({u[i],w[i]});
    }
    for(int i=0;i<n;i++){
        if(adj[i].size()>=3){
            vector<int>edge;
            for(auto [j,W]:adj[i]){
                edge.pb(W);
            }
            sort(all(edge));
            cost[i]=edge[2];
        }
    }
    dep[0]=0;
    up(0,-1);
    down(0,-1);
    for(int i=0;i<n;i++){
        par[i][0]=P[i];
    }
    par[0][0]=0;
    for(int j=1;j<20;j++){
        for(int i=0;i<n;i++){
            par[i][j]=par[par[i][j-1]][j-1];
            C[i][j]=max(C[par[i][j-1]][j-1],C[i][j-1]);
        }
    }
}

int getMinimumFuelCapacity(int x,int y){
    int l=lca(x,y);
    int d=max(f(x,dep[x]-dep[l]),f(y,dep[y]-dep[l]));
    d=max(cost[x],d);
    if(d==2e9) d=-1;
    return d;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3244 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 58 ms 25824 KB Output is correct
10 Correct 86 ms 32096 KB Output is correct
11 Correct 91 ms 31060 KB Output is correct
12 Correct 101 ms 33108 KB Output is correct
13 Correct 94 ms 34916 KB Output is correct
14 Correct 77 ms 25428 KB Output is correct
15 Correct 254 ms 36084 KB Output is correct
16 Correct 238 ms 33748 KB Output is correct
17 Correct 317 ms 38884 KB Output is correct
18 Correct 281 ms 37564 KB Output is correct
19 Runtime error 527 ms 524288 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 179 ms 31552 KB Output is correct
4 Correct 161 ms 32636 KB Output is correct
5 Correct 160 ms 32104 KB Output is correct
6 Correct 156 ms 32428 KB Output is correct
7 Correct 197 ms 32400 KB Output is correct
8 Correct 153 ms 31564 KB Output is correct
9 Correct 160 ms 32516 KB Output is correct
10 Correct 151 ms 31128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3244 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Runtime error 283 ms 524288 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 283 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3244 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 58 ms 25824 KB Output is correct
10 Correct 86 ms 32096 KB Output is correct
11 Correct 91 ms 31060 KB Output is correct
12 Correct 101 ms 33108 KB Output is correct
13 Correct 94 ms 34916 KB Output is correct
14 Correct 77 ms 25428 KB Output is correct
15 Correct 254 ms 36084 KB Output is correct
16 Correct 238 ms 33748 KB Output is correct
17 Correct 317 ms 38884 KB Output is correct
18 Correct 281 ms 37564 KB Output is correct
19 Correct 179 ms 31552 KB Output is correct
20 Correct 161 ms 32636 KB Output is correct
21 Correct 160 ms 32104 KB Output is correct
22 Correct 156 ms 32428 KB Output is correct
23 Correct 197 ms 32400 KB Output is correct
24 Correct 153 ms 31564 KB Output is correct
25 Correct 160 ms 32516 KB Output is correct
26 Correct 151 ms 31128 KB Output is correct
27 Correct 2 ms 3420 KB Output is correct
28 Correct 2 ms 3416 KB Output is correct
29 Correct 2 ms 3420 KB Output is correct
30 Correct 2 ms 3160 KB Output is correct
31 Correct 2 ms 3416 KB Output is correct
32 Correct 2 ms 3420 KB Output is correct
33 Correct 2 ms 3420 KB Output is correct
34 Correct 2 ms 3420 KB Output is correct
35 Correct 2 ms 3420 KB Output is correct
36 Correct 9 ms 6508 KB Output is correct
37 Correct 92 ms 32592 KB Output is correct
38 Correct 87 ms 29820 KB Output is correct
39 Correct 84 ms 27864 KB Output is correct
40 Correct 88 ms 27116 KB Output is correct
41 Correct 91 ms 26652 KB Output is correct
42 Correct 70 ms 24916 KB Output is correct
43 Correct 90 ms 30780 KB Output is correct
44 Correct 87 ms 31612 KB Output is correct
45 Correct 85 ms 32900 KB Output is correct
46 Correct 78 ms 27652 KB Output is correct
47 Correct 18 ms 6748 KB Output is correct
48 Correct 343 ms 35208 KB Output is correct
49 Correct 251 ms 33804 KB Output is correct
50 Correct 239 ms 32900 KB Output is correct
51 Correct 227 ms 32088 KB Output is correct
52 Correct 235 ms 30380 KB Output is correct
53 Correct 150 ms 25324 KB Output is correct
54 Correct 265 ms 35304 KB Output is correct
55 Correct 254 ms 35692 KB Output is correct
56 Correct 266 ms 38384 KB Output is correct
57 Correct 194 ms 33156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 283 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -