Submission #1010142

# Submission time Handle Problem Language Result Execution time Memory
1010142 2024-06-28T11:19:44 Z nickolasarapidis Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 2097152 KB
#include <bits/stdc++.h>
#include "closing.h"
using namespace std;

#define ll long long

const int MAXN = 200000;

vector<pair<int, int> > adj[MAXN];

map<ll, int> m;

int ans = 2;

void dfsPrecompute(int s, int e, vector<ll> dis){
	for(auto u : adj[s]){
		if(u.first != e){
			dfsPrecompute(u.first, s, dis);
			dis[u.first] = dis[s] + u.second;
		}
	}
}

void dfs(int s, int e, vector<ll> C, vector<ll> dis){
	ans++;
	for(auto u : adj[s]){
		if(u.first != e and dis[u.first] <= C[u.first]){
			dfs(u.first, s, C, dis);
		}
	}
}

int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W){
	for(int i = 0; i < N - 1; i++){
		adj[U[i]].push_back({V[i], W[i]});
		adj[V[i]].push_back({U[i], W[i]});
	}

	vector<ll> disX(N);
	vector<ll> disY(N);

	vector<ll> dis(N);
	vector<ll> large(N);

	vector<ll> C(N, 0);

	disX[X] = 0;
	disY[Y] = 0;

	ll sum = 0;

	dfsPrecompute(X, -1, disX);
	dfsPrecompute(Y, -1, disY);

	for(int i = 0; i < N; i++){
		dis[i] = min(disX[i], disY[i]);
		m[dis[i]] = i;
		large[i] = max(disX[i], disY[i]);
	}

	sort(dis.begin(), dis.end());

	for(int i = 2; i < N; i++){
		if(sum += dis[i] <= K){
			if(sum += large[m[dis[i]]] <= K){
				C[i] = large[m[dis[i]]];
			}
			else{
				C[i] = dis[i];
			}
		}
		else{
			break;
		}
	}

	dfs(X, -1, C, dis);
	dfs(Y, -1, C, dis);

	return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 1648700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 1648700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 1648700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 1648700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 1648700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 1648700 KB Time limit exceeded
2 Halted 0 ms 0 KB -