제출 #469218

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
4692182021-08-31 06:57:06amirmohammad_nezami구슬과 끈 (APIO14_beads)C++14
100 / 100
201 ms22284 KiB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define _sz(e) e.size()
#define pii pair <int , int>
#define FAST ios::sync_with_stdio(0); cin.tie(0);
const int maxn = 2e5 + 4 , N = 1e6 + 4 , mod = 1e9 + 7 , INF = 1e9;
int n , dp[maxn] , gp[maxn] , zp[maxn];
vector <pii> edges[maxn];
void dfs(int v , int p = -1 , int W = 0) {
for (auto u : edges[v]) {
if(u.F != p) dfs(u.F , v , u.S);
}
for (auto u : edges[v]) {
if(u.F != p) {
dp[v] += max(dp[u.F] , gp[u.F]);
}
}
for (auto u : edges[v]) {
if(u.F != p) {
int others = dp[v] - max(dp[u.F] , gp[u.F]);
gp[v] = max(gp[v] , dp[u.F] + u.S + W + others);
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...