Submission #131252

#TimeUsernameProblemLanguageResultExecution timeMemory
131252arthurconmyCrocodile's Underground City (IOI11_crocodile)C++14
0 / 100
5 ms504 KiB
/* Arthur Conmy / arthurconmy */ #include <iostream> #include <fstream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <map> #include <queue> #include <bitset> #include <random> #include <stack> #include <deque> #include <chrono> #ifndef ARTHUR_LOCAL #include "crocodile.h" #endif using namespace std; using ll = long long; #define ff first #define ss second const int MAXN=1001; vector<pair<int,ll>> adj[MAXN]; bool vis[MAXN]; bool leaf[MAXN]; void update(ll NEW, ll &FIR, ll &SEC) { if(NEW<=FIR) { SEC=FIR; FIR=NEW; } else { SEC=min(SEC,NEW); } } ll dfs(int v) { vis[v]=1; ll best=1e18; ll second_best=1e18; for(auto u:adj[v]) { if(vis[u.ff]) continue; if(leaf[u.ff]) { update(u.ss, best, second_best); } else { update(u.ss+dfs(u.ff), best, second_best); } } return second_best; } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for(int i=0; i<N-1; i++) { adj[R[i][0]].push_back(make_pair(R[i][1],ll(L[i]))); adj[R[i][1]].push_back(make_pair(R[i][0],ll(L[i]))); } for(int i=0; i<K; i++) { leaf[P[i]]=1; } ll ans=0; for(int i=0; i<N; i++) { if(!leaf[i]) { ll cur=dfs(i); // cout << i << " " << cur << endl; ans=max(ans,cur); for(int j=0; j<N; j++) { vis[j]=0; } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...