# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
31739 | 2017-09-03T08:05:46 Z | top34051 | 구슬과 끈 (APIO14_beads) | C++14 | 6 ms | 4992 KB |
#include<bits/stdc++.h> using namespace std; #define maxn 200005 #define inf (long long)2e10 int n; int par[maxn]; long long mx[2], mem[maxn][2]; vector<int> p; vector<pair<int,long long> > from[maxn]; void dfs(int x) { int i,y; for(i=0;i<from[x].size();i++) { y = from[x][i].first; if(y==par[x]) continue; par[y] = x; dfs(y); } p.push_back(x); } void upd(long long val) { for(int i=0;i<2;i++) if(mx[i]<val) swap(mx[i],val); } main() { int i,x,y,now; long long val, sum, temp; scanf("%d",&n); for(i=0;i<n-1;i++) { scanf("%d%d%lld",&x,&y,&val); from[x].push_back({y,val}); from[y].push_back({x,val}); } par[1] = 0; dfs(1); for(now=0;now<p.size();now++) { x = p[now]; //Prep sum = 0; mx[0] = mx[1] = -inf; for(i=0;i<from[x].size();i++) { y = from[x][i].first; val = from[x][i].second; temp = max(mem[y][0], mem[y][1] + val); if(y!=par[x]) { sum += temp; upd(mem[y][0] + val - temp); } } //Don't Fix mem[x][0] = max(sum, sum + mx[0] + mx[1]); //Fix mem[x][1] = max(-inf, sum + mx[0]); // printf("mem %d : %lld and %lld\n",x,mem[x][0],mem[x][1]); } printf("%lld",mem[x][0]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 6 ms | 4992 KB | Output is correct |
4 | Correct | 6 ms | 4992 KB | Output is correct |
5 | Correct | 5 ms | 4992 KB | Output is correct |
6 | Incorrect | 6 ms | 4992 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 6 ms | 4992 KB | Output is correct |
4 | Correct | 6 ms | 4992 KB | Output is correct |
5 | Correct | 5 ms | 4992 KB | Output is correct |
6 | Incorrect | 6 ms | 4992 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 6 ms | 4992 KB | Output is correct |
4 | Correct | 6 ms | 4992 KB | Output is correct |
5 | Correct | 5 ms | 4992 KB | Output is correct |
6 | Incorrect | 6 ms | 4992 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 6 ms | 4992 KB | Output is correct |
4 | Correct | 6 ms | 4992 KB | Output is correct |
5 | Correct | 5 ms | 4992 KB | Output is correct |
6 | Incorrect | 6 ms | 4992 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |