Submission #709650

#TimeUsernameProblemLanguageResultExecution timeMemory
709650therealpainCrocodile's Underground City (IOI11_crocodile)C++17
46 / 100
117 ms262144 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; vector <pair <int, int>> adj[N]; bool special[N]; int n, m, k; namespace sub1 { long long dist[1000][1000]; long long dp[1000][2]; void dfs1(int u, int p, int root) { for (auto [v, w] : adj[u]) { if (v == p || v == root) continue; dist[root][v] = dist[root][u] + w; dfs1(v, u, root); } } void dfs2(int u, int p) { if (special[u] == true) { dp[u][0] = dp[u][1] = 0; return; } for (auto [v, w] : adj[u]) { if (v == p) continue; dfs2(v, u); if (dp[u][0] > dp[v][1] + w) { dp[u][1] = dp[u][0]; dp[u][0] = dp[v][1] + w; } else if (dp[u][1] > dp[v][1] + w) { dp[u][1] = dp[v][1] + w; } } } long long solve() { for (int i = 0; i < n; ++i) { dfs1(i, i, i); } memset(dp, 0x3f, sizeof dp); dfs2(0, 0); return dp[0][1]; } }; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { n = N; m = M; k = K; for (int i = 0; i < m; ++i) { int u = R[i][0], v = R[i][1], w = L[i]; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } for (int i = 0; i < k; ++i) { special[P[i]] = true; } return sub1::solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...