답안 #1010176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010176 2024-06-28T12:34:43 Z nickolasarapidis 봉쇄 시간 (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];

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

map<ll, int> m;

int ans = 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);

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

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 159660 KB Output is correct
2 Correct 442 ms 405452 KB Output is correct
3 Execution timed out 1108 ms 2097152 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Incorrect 2 ms 8280 KB 1st lines differ - on the 1st token, expected: '30', found: '16'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Incorrect 2 ms 8280 KB 1st lines differ - on the 1st token, expected: '30', found: '16'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Incorrect 2 ms 8280 KB 1st lines differ - on the 1st token, expected: '30', found: '16'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -