Submission #1316286

#TimeUsernameProblemLanguageResultExecution timeMemory
1316286aaaaaaaaCrocodile's Underground City (IOI11_crocodile)C++20
46 / 100
182 ms327680 KiB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

const int mxN = 1005;

vector<pair<int, int>> adj[mxN];
int dp[mxN];

void dfs(int u = 0, int par = -1){
    vector<int> cost;
    dp[u] = 0;
    for(auto [v, w] : adj[u]){
        if(v ^ par){
            dfs(v, u);
            cost.push_back(dp[v] + w);
        }
    }
    sort(cost.begin(), cost.end());
    if(cost.size()) dp[u] = cost[1];
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  for(int i = 0; i < N; ++i){
    adj[i].clear();
    dp[i] = 0;
  }

  for(int i = 0; i < M; ++i){
    adj[R[i][0]].push_back({R[i][1], L[i]});
    adj[R[i][1]].push_back({R[i][0], L[i]});
  }

  dfs();

  return dp[0];
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...