Submission #106244

#TimeUsernameProblemLanguageResultExecution timeMemory
106244tincamateiCrocodile's Underground City (IOI11_crocodile)C++14
46 / 100
7 ms2944 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const int INF = 1000000001; vector<pair<int, int> > graph[MAX_N]; int dp[MAX_N]; bool proc[MAX_N]; void dfs(int nod) { if(!proc[nod]) { int best[2]; proc[nod] = true; dp[nod] = INF; best[0] = best[1] = INF; for(auto it: graph[nod]) { dfs(it.first); int cost = dp[it.first] + it.second; if(cost <= best[0]) { best[1] = best[0]; best[0] = cost; } else if(cost <= best[1]) best[1] = cost; } dp[nod] = best[1]; } } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for(int i = 0; i < M; ++i) { graph[R[i][0]].push_back(make_pair(R[i][1], L[i])); graph[R[i][1]].push_back(make_pair(R[i][0], L[i])); } for(int i = 0; i < N; ++i) dp[i] = INF; for(int i = 0; i < K; ++i) { dp[P[i]] = 0; proc[P[i]] = true; } dfs(0); return dp[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...