Submission #672158

# Submission time Handle Problem Language Result Execution time Memory
672158 2022-12-14T21:51:56 Z Hacv16 Crocodile's Underground City (IOI11_crocodile) C++17
0 / 100
113 ms 190888 KB
#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){
		if(ex[u]) dp[u] = 0;
		else dp[u] = INF;

		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); }
	}

	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]);
	}

	for(int i = 0; i < k; i++)
		ex[P[i]] = true;

	calcdp(0, -1);
	dfs(0, -1);

	return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 190888 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 190888 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 190888 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -