답안 #42564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42564 2018-02-28T06:20:44 Z comfile 경주 (Race) (IOI11_race) C++14
0 / 100
3000 ms 4984 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long int ll;
using namespace std;
const int N = 200010;
int n,k,sz[N],dead[N],ans;
vector<pii> g[N];
void get_sz(int cur,int prev){
    sz[cur] = 1;
    for(auto &x : g[cur]) if(!dead[x.first] && x.first!=prev){
        get_sz(x.first,cur);
      sz[cur] += sz[x.first];
    }
}
int dfs(int cur,int prev,int tot){
    for(auto &x : g[cur]) if(!dead[x.first] && x.first!=prev){
        if(sz[x.first]>(tot/2)) return dfs(x.first,cur,tot);
    }
    return cur;
}
int one(int start){
    get_sz(start,-1);
    return dfs(start,-1,sz[start]);
}
void rec(int cur){
    int c = one(cur);
    dead[c] = 1;
    for(auto &x : g[c]) if(!dead[x.first]) rec(x.first);
    map<int,int> cnt;
    function<void (int,int,int)> dfs3 = [&](int cu,int st,int _depth){
        if(_depth>k) return;
        cnt[_depth] = cnt[_depth]?min(cnt[_depth],st):st;
        for(auto &x : g[cu]) if(!dead[x.first])
            dfs3(x.first,st+1,_depth+x.second);
    };
    function<void (int,int,int)> dfs4 = [&](int cu,int st,int _depth){
        if(_depth>k) return;
        if(cnt[k-_depth]) ans = min(ans,st+cnt[k-_depth]);
        for(auto &x : g[cu]) if(!dead[x.first])
            dfs4(x.first,st+1,_depth+x.second);
    };
    dfs3(c,0,0);
    if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
    for(auto &x : g[c]) if(!dead[x.first]){
        dfs4(x.first,1,x.second);
        dfs3(x.first,1,x.second);
    }
    dead[c] = 0;
}
int best_path(int _n,int _k,int h[][2],int l[]){
    ans = 1e9;
    n = _n; k = _k;
    for(int i=0;i<n-1;i++){
        int a = h[i][0];
        int b = h[i][1];
        int c = l[i];
        g[a].pb(mp(b,c));
        g[b].pb(mp(a,c));
    }
    rec(0);
    if(ans>=1e9) ans = -1;
    return ans;
}

Compilation message

race.cpp: In function 'void rec(int)':
race.cpp:45:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
     ^~
race.cpp:45:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
                                       ^~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3053 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3053 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3053 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3053 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -