제출 #1051679

#제출 시각아이디문제언어결과실행 시간메모리
1051679Nika533경주 (Race) (IOI11_race)C++17
100 / 100
720 ms195928 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;

const int N=2e5+5;

int n,k,ans=1e9;
int depth[N];
long long d[N];
vector<pair<int,int>> g[N];
map<pair<int,int>,int> edge;
map<long long,long long> mymap[N];

void dfs(int x, int p) {
    d[x]=d[p]+edge[{x,p}]; depth[x]=depth[p]+1;
    mymap[x][d[x]]=depth[x];
    for (auto A:g[x]) {
        int y=A.f,w=A.s;
        if (y==p) continue;
        dfs(y,x);
        int sx=mymap[x].size(),sy=mymap[y].size();
        if (sx<sy) swap(mymap[x],mymap[y]);
        for (auto AA:mymap[y]) {
            long long D=AA.f;
            long long DEPTH=AA.s;
            if (DEPTH==0) continue;
            if (mymap[x][k+2*d[x]-D]>0) {
                int val=mymap[x][k+2*d[x]-D]+DEPTH-2*depth[x];
                ans=min(ans,val);
            }
        }
        for (auto AA:mymap[y]) {
            long long D=AA.f;
            long long DEPTH=AA.s;
            if (DEPTH==0) continue;
            if (mymap[x][D]==0) mymap[x][D]=DEPTH;
            else mymap[x][D]=min(mymap[x][D],DEPTH);
        }
    }
    // cout<<"X "<<x<<" "<<ans<<endl;
    // for (auto A:mymap[x]) {
    //     cout<<A.f<<" "<<A.s<<endl;
    // }
}

int best_path(int N, int K, int H[][2], int L[]) {
    n=N; k=K; edge[{0,0}]=1;
    for (int i=0; i<n-1; i++) {
        int a=H[i][1],b=H[i][0],c=L[i];
        g[a].pb({b,c}); g[b].pb({a,c});
        edge[{a,b}]=edge[{b,a}]=c;
    }
    dfs(0,0);
    if (ans==1000000000) ans=-1;
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'void dfs(int, int)':
race.cpp:20:19: warning: unused variable 'w' [-Wunused-variable]
   20 |         int y=A.f,w=A.s;
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...