답안 #777085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777085 2023-07-08T15:58:34 Z LeaRouse 경주 (Race) (IOI11_race) C++14
21 / 100
3000 ms 22028 KB
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define ff first
using namespace std;
const int MAX=2e5+5;
vector<pair<int,int>>v[MAX];
int D[MAX],Ni[MAX],vis[MAX],pa[MAX][25];

void st(int n){
    for(int j=1;j<20;j++){
        pa[0][j]=0;
        for(int i=1;i<n;i++){
            pa[i][j]=pa[pa[i][j-1]][j-1];
        }
    }
    
}

int lca(int x,int y){
    if(Ni[y]>Ni[x])   swap(x,y);
    int dif=Ni[x]-Ni[y];
    for(int i=20;i>=0;i--){
        if(dif&(1<<i)){
            dif-=(1<<i);
            x=pa[x][i];
        }
    }
    if(y==x)    return x;
    for(int i=18;i>=0;i--){
        if(pa[x][i]!=pa[y][i]){
            x=pa[x][i];
            y=pa[y][i];
        }
    }
    return pa[x][0];

}

void dfs(int u){
    vis[u]=1;
    for(auto it:v[u]){
        if(vis[it.ff]) continue;
        D[it.ff]=D[u]+it.second;
        pa[it.ff][0]=u;
        Ni[it.ff]=Ni[u]+1;
        dfs(it.ff);
    }
}

int best_path(int n,int k,int w[][2],int nc[]){
    for(int i=0;i<n;i++){
        v[w[i][0]].push_back({w[i][1],nc[i]});
        v[w[i][1]].push_back({w[i][0],nc[i]});
    }
    dfs(0);
    st(n);
    int b=1e9;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int a=lca(i,j);
            if(D[i]+D[j]-2*D[a]==k){
                b=min(Ni[i]+Ni[j]-2*Ni[a],b);
            }
        }
    }
    if(b==1e9)  b=-1;
    return b;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5008 KB Output is correct
8 Correct 2 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 3 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 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5008 KB Output is correct
8 Correct 2 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 3 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 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 31 ms 5200 KB Output is correct
22 Correct 36 ms 5076 KB Output is correct
23 Correct 36 ms 5076 KB Output is correct
24 Correct 39 ms 5076 KB Output is correct
25 Correct 40 ms 5076 KB Output is correct
26 Correct 31 ms 5144 KB Output is correct
27 Correct 32 ms 5180 KB Output is correct
28 Correct 38 ms 5192 KB Output is correct
29 Correct 32 ms 5204 KB Output is correct
30 Correct 32 ms 5200 KB Output is correct
31 Correct 32 ms 5200 KB Output is correct
32 Correct 33 ms 5196 KB Output is correct
33 Correct 39 ms 5076 KB Output is correct
34 Correct 38 ms 5076 KB Output is correct
35 Correct 35 ms 5172 KB Output is correct
36 Correct 28 ms 5076 KB Output is correct
37 Correct 32 ms 5096 KB Output is correct
38 Correct 38 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5008 KB Output is correct
8 Correct 2 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 3 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 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Execution timed out 3073 ms 22028 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5008 KB Output is correct
8 Correct 2 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 3 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 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 31 ms 5200 KB Output is correct
22 Correct 36 ms 5076 KB Output is correct
23 Correct 36 ms 5076 KB Output is correct
24 Correct 39 ms 5076 KB Output is correct
25 Correct 40 ms 5076 KB Output is correct
26 Correct 31 ms 5144 KB Output is correct
27 Correct 32 ms 5180 KB Output is correct
28 Correct 38 ms 5192 KB Output is correct
29 Correct 32 ms 5204 KB Output is correct
30 Correct 32 ms 5200 KB Output is correct
31 Correct 32 ms 5200 KB Output is correct
32 Correct 33 ms 5196 KB Output is correct
33 Correct 39 ms 5076 KB Output is correct
34 Correct 38 ms 5076 KB Output is correct
35 Correct 35 ms 5172 KB Output is correct
36 Correct 28 ms 5076 KB Output is correct
37 Correct 32 ms 5096 KB Output is correct
38 Correct 38 ms 5076 KB Output is correct
39 Execution timed out 3073 ms 22028 KB Time limit exceeded
40 Halted 0 ms 0 KB -