# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
248900 | patrikpavic2 | 구슬과 끈 (APIO14_beads) | C++17 | 1094 ms | 8568 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <unordered_map>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef pair < int, int > pii;
typedef long long ll;
const int N = 2e5 + 500;
const ll INF = 1e15;
vector < pii > v[N];
unordered_map < ll, ll > dp[3];
int n;
ll f(int x, int fl, int lst){
if(dp[fl][x * N + lst] != 0)
return dp[fl][x * N + lst] - 69420;
ll sm = 0, dod = -INF;
for(pii nxt : v[x]){
if(nxt.X == lst) continue;
ll opt = max(f(nxt.X, 0, x), f(nxt.X, 1, x) + (ll)nxt.Y);
sm += opt;
dod = max(dod, f(nxt.X, 2, x) + nxt.Y - opt);
}
return (dp[fl][x * N + lst] = sm + dod * (fl == 1) + 69420) - 69420;
}
int main(){
scanf("%d", &n);
for(int i = 1;i < n;i++){
int x, y, z; scanf("%d%d%d", &x, &y, &z);
v[x].PB({y, z}), v[y].PB({x, z});
}
ll sol = 0;
for(int i = 1;i <= n;i++)
sol = max(sol, f(i, 0, i));
printf("%lld\n", sol);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |