Submission #1076456

# Submission time Handle Problem Language Result Execution time Memory
1076456 2024-08-26T14:03:48 Z rayan_bd Race (IOI11_race) C++17
0 / 100
3000 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int mxN = 1005;
const int INF = (int)1e9;

vector<pair<int,int>> adj[mxN];

int find(int src,int k){
    if(k<0) return INF;
    if(k==0) return 0;
    int ans=INF;
    for(auto it:adj[src]){
        ans=min(ans,find(it.first,k-it.second)+1);
    }
    return ans;
}

int best_path(int n,int k,int h[][2],int l[]){

    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 ans=INF;

    for(int i=0;i<n;++i){
        ans=min(ans,find(i,k));
    }

    if(ans==INF) return -1;
    return ans;
}

/*int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif

    int n,k;cin>>n>>k;
    int h[n-1][2],l[n-1];
    for(int i=0;i<n-1;++i){
        cin>>h[i][0]>>h[i][1];
    }
    for(int i=0;i<n-1;++i){
        cin>>l[i];
    }
    
    cout<<best_path(n,k,h,l);

    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Execution timed out 3076 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3076 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3076 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3076 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -