Submission #426287

#TimeUsernameProblemLanguageResultExecution timeMemory
426287SAADRace (IOI11_race)C++17
21 / 100
3072 ms11532 KiB
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
int n , k ;
bool visa[(int)3 * 100000];
vector <pair<int,int>> x[200002];
int best_path( int N, int K, int H[][2] ,int L[]) {
    n = N;k = K;
    for ( int i = 0 ; i < n-1 ; i++ ) {
        x[H[i][0]].pb( { L[i] , H[i][1] } );
        swap(H[i][0],H[i][1]);
        x[H[i][0]].pb( { L[i] , H[i][1] } );
    }
    int mn = (int)1e6;
    for ( int i = 0; i < n; i++ ) {
        memset(visa,0,sizeof(visa));
        queue <pair<ll,int>> q ;
        q.push({0,i});
        int z = 1 , layer = 0 ;
        while ( !q.empty() ) {
            if ( layer > k ) break;
            int a = q.front().S; ll cst = q.front().F;
            q.pop();
            visa[a] = true;
            cst *= -1 ;
            if (cst == k) mn = min(mn,layer);
            for (auto i:x[a]) {
                if ( visa[i.S] ) continue ;
                q.push( { -(cst+i.F) , i.S } );
            }
            z--;
            if ( !z ) {
                layer++;
                z = q.size();
            }
        }
    }
    return (mn==(int)1e6?-1:mn) ;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...