Submission #672161

# Submission time Handle Problem Language Result Execution time Memory
672161 2022-12-14T22:02:53 Z Hacv16 Crocodile's Underground City (IOI11_crocodile) C++17
46 / 100
115 ms 191212 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){ 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 time Memory Grader output
1 Correct 43 ms 94164 KB Output is correct
2 Correct 45 ms 94300 KB Output is correct
3 Correct 43 ms 94276 KB Output is correct
4 Correct 47 ms 94272 KB Output is correct
5 Correct 44 ms 94368 KB Output is correct
6 Correct 44 ms 94292 KB Output is correct
7 Correct 44 ms 94316 KB Output is correct
8 Correct 43 ms 94424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94164 KB Output is correct
2 Correct 45 ms 94300 KB Output is correct
3 Correct 43 ms 94276 KB Output is correct
4 Correct 47 ms 94272 KB Output is correct
5 Correct 44 ms 94368 KB Output is correct
6 Correct 44 ms 94292 KB Output is correct
7 Correct 44 ms 94316 KB Output is correct
8 Correct 43 ms 94424 KB Output is correct
9 Runtime error 115 ms 191212 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94164 KB Output is correct
2 Correct 45 ms 94300 KB Output is correct
3 Correct 43 ms 94276 KB Output is correct
4 Correct 47 ms 94272 KB Output is correct
5 Correct 44 ms 94368 KB Output is correct
6 Correct 44 ms 94292 KB Output is correct
7 Correct 44 ms 94316 KB Output is correct
8 Correct 43 ms 94424 KB Output is correct
9 Runtime error 115 ms 191212 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -