Submission #26944

# Submission time Handle Problem Language Result Execution time Memory
26944 2017-07-07T11:23:15 Z repeating Race (IOI11_race) C++11
0 / 100
11 ms 9720 KB
#include <bits/stdc++.h>
//#include "race.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
//#define MAX_N 500000

using namespace std;
const long long INF = 1e9+5e8;
const int MX=200009;
int n,k;
int par[MX];
int sub[MX];
int dis[MX];
int ways[MX];
int t[MX*5];
vector<pii> adj[MX];
vector<int> v;
bool blocked[MX];
stack<int> st;
int DFS(int ver){
    int ret=1;
    v.pb(ver);
    for(auto i : adj[ver]){
        if(i.F==par[ver]||blocked[i.F])C;
        par[i.F]=ver;
        ret+=DFS(i.F);
    }
    sub[ver]=ret;
    R ret;
}
int dfs(int ver,ll d,int w,int p){
    int ret=INF;
    st.P(ver);
    dis[ver]=d;
    ways[ver]=w;

    if(k>=d){
//        cout<<t[k-d]<<endl;
        ret=min(ret,t[k-d]+w);
    }
    for(auto i : adj[ver]){
        if(i.F==p||blocked[i.F])C;
        ret=min(ret,dfs(i.F,d+i.S,w+1,ver));
    }
    R ret;
}
int solve(int ver){
    int ret=INF;
    for(auto i : adj[ver]){
        if(blocked[i.F])C;
        ret=min(ret,dfs(i.F,i.S,1,ver));
        W(!st.empty()){
            if(st.top()>=1000000){
                st.pop();
                C;
            }
            t[dis[st.top()]]=min(t[dis[st.top()]],ways[st.top()]);
            st.pop();
        }
    }
    R ret;
}
int creat(int ver){
    v.clear();
    int ret=INF;
    DFS(ver);
    int mn=v.SI,pos=ver;
    for(auto i : v){
        int mx=v.SI-sub[i];
        for(auto j : adj[i]){
            if(blocked[j.F]||j.F==par[i])C;
            mx=max(mx,sub[j.F]);
        }
        if(mx<mn){
            mn=mx;
            pos=i;
        }
    }
    t[0]=0;
    ret=solve(pos);
    blocked[pos]=1;
    for(auto i : v){
        par[i]=-1;
        t[i]=INF;
    }
    for(auto i : adj[pos]){
        if(blocked[i.F])C;
        ret=min(ret,creat(i.F));
    }
    R ret;
}
int best_path(int N, int K, int H[][2], int L[])
{
    fill(t,t+1000000,INF);
    MEM(par,-1);
    n=N,k=K;
    for(int i=0;i<n-1;i++){
        adj[H[i][0]].pb({H[i][1],L[i]});
        adj[H[i][1]].pb({H[i][0],L[i]});
    }
    int res=creat(0);
    if(res==INF)R -1;
    else R res;
}

# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -