제출 #917205

#제출 시각아이디문제언어결과실행 시간메모리
917205zyq181Truck Driver (IOI23_deliveries)C++17
29 / 100
74 ms7764 KiB
#include "deliveries.h"
#include <bits/stdc++.h>
using namespace std;

int N;
vector<pair<int, int> > adjList[1010];
long long paredge[1010];
long long sbtree[1010];
long long tot;
long long ans;
int w[1010];

void dfs(int n, int p = -1){
	sbtree[n]+=w[n];
	for(auto it: adjList[n]){
		int x, y;
		x = it.first;
		y = it.second;
		if(x == p) continue;
		paredge[x] = y;
		dfs(x, n);
		sbtree[n] += sbtree[x];
	}
}



void init(int NN, std::vector<int> U, std::vector<int> V, std::vector<int> T, std::vector<int> W) {
	N = NN;
	for(int a=0; a<N-1; a++){
		adjList[U[a]].push_back({V[a], T[a]});
		adjList[V[a]].push_back({U[a], T[a]});
	}
	W[0]++;
	for(int a=0; a<N; a++){
		w[a] = W[a];
		tot += W[a];
	}
	return;
}

long long max_time(int S, int X) {
	for(int a=0; a<N; a++) sbtree[a] = 0;
	ans = 0;
	tot -= w[S];
	w[S] = X;
	if(S == 0) w[0]++;
	tot += w[S];
	dfs(0);
	for(int a=1; a<N; a++){
		if(tot/2 < sbtree[a]){
			ans += 2LL * (tot - sbtree[a]) * paredge[a];
		}
		else{
			ans += 2LL * sbtree[a] * paredge[a];
		}
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...