답안 #248900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248900 2020-07-13T17:20:45 Z patrikpavic2 구슬과 끈 (APIO14_beads) C++17
28 / 100
1000 ms 8568 KB
#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;
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
beads.cpp:41:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, z; scanf("%d%d%d", &x, &y, &z);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 3 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 8 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 3 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 8 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 17 ms 6656 KB Output is correct
24 Correct 19 ms 6656 KB Output is correct
25 Correct 18 ms 6656 KB Output is correct
26 Correct 34 ms 8448 KB Output is correct
27 Correct 39 ms 8568 KB Output is correct
28 Execution timed out 1094 ms 6836 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 3 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 8 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 17 ms 6656 KB Output is correct
24 Correct 19 ms 6656 KB Output is correct
25 Correct 18 ms 6656 KB Output is correct
26 Correct 34 ms 8448 KB Output is correct
27 Correct 39 ms 8568 KB Output is correct
28 Execution timed out 1094 ms 6836 KB Time limit exceeded
29 Halted 0 ms 0 KB -