#include "deliveries.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 1005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
vector<pi>adj[MAXN];
int n;
int W[MAXN];
void init(int N, std::vector<int> U, std::vector<int> V, std::vector<int> T, std::vector<int> W) {
n=N;
for(int i=0;i<n-1;i++){
adj[U[i]].push_back({V[i],T[i]});
adj[V[i]].push_back({U[i],T[i]});
}
for(int i=0;i<n;i++){
::W[i]=W[i];
}
W[0]+=2;
}
int sz[MAXN];
int res=0;
void dfs(int x, int p, int vcost){
sz[x]+=W[x];
for(auto v:adj[x])if(v.first!=p){
dfs(v.first,x,v.second);
sz[x]+=sz[v.first];
}
}
void get(int x, int p, int vcost){
for(auto v:adj[x])if(v.first!=p){
get(v.first,x,v.second);
}
debug(x,vcost,sz[x],sz[0]-sz[x]);
res += vcost * 2 * min(sz[x],sz[0]-sz[x]);
}
int solve(){
memset(sz,0,sizeof sz);
res=0;
dfs(0,-1,0);
get(0,-1,0);
return res;
}
long long max_time(int S, int X) {
W[S]=X;
if(S==0){
W[S]++;
}
return solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
7760 KB |
Output is correct |
2 |
Correct |
91 ms |
7412 KB |
Output is correct |
3 |
Incorrect |
88 ms |
7760 KB |
3rd lines differ - on the 1st token, expected: '86741232', found: '86741080' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '1627540', found: '1617480' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
7760 KB |
Output is correct |
2 |
Correct |
91 ms |
7412 KB |
Output is correct |
3 |
Incorrect |
88 ms |
7760 KB |
3rd lines differ - on the 1st token, expected: '86741232', found: '86741080' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
7760 KB |
Output is correct |
2 |
Correct |
91 ms |
7412 KB |
Output is correct |
3 |
Incorrect |
88 ms |
7760 KB |
3rd lines differ - on the 1st token, expected: '86741232', found: '86741080' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
7760 KB |
Output is correct |
2 |
Correct |
91 ms |
7412 KB |
Output is correct |
3 |
Incorrect |
88 ms |
7760 KB |
3rd lines differ - on the 1st token, expected: '86741232', found: '86741080' |
4 |
Halted |
0 ms |
0 KB |
- |