# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552266 | QuantumK9 | Crocodile's Underground City (IOI11_crocodile) | C++17 | 3 ms | 852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
vector< vector< pair<int,int> > > connect;
vector<bool> explored, isEnd;
int delve( int i ){
explored[i] = true;
if( isEnd[i] ){ return 0; }
vector<int> poss;
for( int j = 0; j < connect[i].size(); j++ ){
if ( !explored[ connect[i][j].first ] ){
int val = delve( connect[i][j].first );
if ( val != -1 ){
poss.pb( val + connect[i][j].second );
}
}
}
sort( poss.begin(), poss.end() );
if ( poss.size() < 2 ){ return -1; }
else{ return poss[1]; }
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
// set up helper values
connect.resize(N);
for( int i = 0; i < M; i++ ){
connect[ R[i][0] ].pb( mp( R[i][1], L[i] ) );
connect[ R[i][1] ].pb( mp( R[i][0], L[i] ) );
}
if ( M == N-1 ){
// do my thing -- pyramid explore
explored.resize(N, false);
isEnd.resize(N, false);
for( int i = 0; i < K; i++ ){ isEnd[ P[i] ] = true; }
return delve(0);
}
else{
int vc[N];
memset( vc, 0, sizeof vc );
// recursive backtracking .. ? djkistras from the starting points -- GENIUS
priority_queue< pair<ll,ll>, vector< pair<ll,ll> >, greater< pair<ll,ll> > > PQ;
for( int i = 0; i < K; i++ ){ PQ.push( mp( 0, P[i]) ); vc[ P[i] ]++; }
while ( !PQ.empty() ){
ll dist = PQ.top().first;
ll ind = PQ.top().second;
PQ.pop();
if ( vc[ind] == 2 ){ continue; } // already solved
if ( vc[ind] == 0 ){ vc[ind]++; continue; }
// vc[ind] = 1, which means we are at the second-shortest path atm
if( ind == 0 ){ return dist; }
for( int i = 0; i < connect[ind].size(); i++ ){
if( vc[ connect[ind][i].first ] < 2 ){
PQ.push( mp( dist+connect[ind][i].second, connect[ind][i].first ) );
}
}
}
return -1;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |