답안 #1010182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010182 2024-06-28T12:50:24 Z nickolasarapidis 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 2097152 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int MAXN = 200000;

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

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

map<ll, int> m;

int ans = 0;
int ans2 = 0;

void dfsPrecompute(int s, int e, int X){
	for(auto u : adj[s]){
		if(u.first != e){
			if(X == 0){
				disX[u.first] = disX[s] + u.second;
				dfsPrecompute(u.first, s, X);
			}
			else{
				disY[u.first] = disY[s] + u.second;
				dfsPrecompute(u.first, s, X);
			}
		}
	}
}

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

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<tuple<ll, ll, int> > dis(N);

	vector<ll> C(N, 0);
	vector<ll> C2(N, 0);

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

	ll sum = 0;

	dfsPrecompute(X, -1, 0);
	dfsPrecompute(Y, -1, 1);

	for(int i = 0; i < N; i++){
		get<0>(dis[i]) = min(disX[i], disY[i]);
		get<1>(dis[i]) = max(disX[i], disY[i]);
		get<2>(dis[i]) = i;
	}

	sort(dis.begin(), dis.begin() + N - 1);

	for(int i = 0; i < N; i++){
		if(get<2>(dis[i]) != X and get<2>(dis[i]) != Y){
			if(sum + get<0>(dis[i]) <= K){
				if(sum + get<1>(dis[i]) <= K){
					C[get<2>(dis[i])] = get<1>(dis[i]);
					sum += C[get<2>(dis[i])];
				}
				else{
					C[get<2>(dis[i])] = get<0>(dis[i]);
					sum += C[get<2>(dis[i])];
				}
			}
			else{
				break;
			}
		}
	}

	dfs(X, -1, C, 0);
	dfs(Y, -1, C, 1);
	
	ans2 = ans;
	ans = 0;
	
	for(int i = 0; i < N; i++){
		if(sum + get<0>(dis[i]) <= K){
			if(sum + get<1>(dis[i]) <= K){
				C2[get<2>(dis[i])] = get<1>(dis[i]);
				sum += C2[get<2>(dis[i])];
			}
			else{
				C2[get<2>(dis[i])] = get<0>(dis[i]);
				sum += C2[get<2>(dis[i])];
			}
		}
		else{
			break;
		}
	}
	
	dfs(X, -1, C2, 0);
	dfs(Y, -1, C2, 1);

	return max(ans, ans2);
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1129 ms 1849940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 160832 KB Output is correct
2 Correct 479 ms 406496 KB Output is correct
3 Execution timed out 1140 ms 2097152 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8028 KB Output is correct
2 Incorrect 2 ms 8028 KB 1st lines differ - on the 1st token, expected: '30', found: '16'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8028 KB Output is correct
2 Incorrect 2 ms 8028 KB 1st lines differ - on the 1st token, expected: '30', found: '16'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8028 KB Output is correct
2 Incorrect 2 ms 8028 KB 1st lines differ - on the 1st token, expected: '30', found: '16'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1129 ms 1849940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1129 ms 1849940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1129 ms 1849940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1129 ms 1849940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1129 ms 1849940 KB Time limit exceeded
2 Halted 0 ms 0 KB -