Submission #672161

#TimeUsernameProblemLanguageResultExecution timeMemory
672161Hacv16Crocodile's Underground City (IOI11_crocodile)C++17
46 / 100
115 ms191212 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; } ll mn1 = INF, mn2 = 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); ll cur = dp[v] + c; if(cur < mn1){ swap(mn1, mn2); swap(mn1, cur); } else if(cur < mn2){ swap(mn2, cur); } } dp[u] = mn2; } int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){ assert(m == n - 1); 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); return dp[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...