Submission #672160

#TimeUsernameProblemLanguageResultExecution timeMemory
672160Hacv16Crocodile's Underground City (IOI11_crocodile)C++17
0 / 100
43 ms94156 KiB
#include<bits/stdc++.h> #include "crocodile.h" using namespace std; typedef long long ll; const int MAX = 2e6 + 15; const ll INF = 5e18 + 50; #define fr first #define sc second ll dp[MAX], ans; bool ex[MAX]; vector<ll> adj[MAX], w[MAX]; void calcdp(int u, int p){ if(adj[u].size() == 1){ dp[u] = 0; return; } dp[u] = INF; for(int i = 0; i < (int) adj[u].size(); i++){ ll v = adj[u][i], c = w[u][i]; if(v == p) continue; calcdp(v, u); dp[u] = min(dp[u], dp[v] + c); } } void dfs(int u, int p){ pair<ll, ll> f1 = {INF, INF}, f2 = {INF, INF}; for(int i = 0; i < (int) adj[u].size(); i++){ int v = adj[u][i], c = w[u][i]; if(v == p) continue; pair<ll, ll> cur = {dp[v] + c, v}; if(cur.fr < f1.fr){ swap(f1, f2); swap(cur, f1); } else if(cur.fr < f2.fr){ swap(f2, cur); } } if(f2.sc == INF) return; ans += f2.fr; dfs(f2.sc, u); } int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){ for(int i = 0; i < m; i++){ int u = R[i][0], v = R[i][1]; adj[u].push_back(v); adj[v].push_back(u); w[u].push_back(L[i]); w[v].push_back(L[i]); } calcdp(0, -1); dfs(0, -1); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...