Submission #122352

# Submission time Handle Problem Language Result Execution time Memory
122352 2019-06-28T05:24:42 Z 임유진(#2991) Beads and wires (APIO14_beads) C++14
28 / 100
1000 ms 6144 KB
#include<stdio.h>
#include<vector>

using namespace std;

#define MAXN 200005

typedef long long lint;
typedef pair<lint, lint> pll;

const lint LINF=1ll<<50;
vector<pll> e[MAXN];
pll par[MAXN];
lint D[MAXN], P[MAXN];

void dfs(lint x){
	lint psum=0ll;
	lint mx[2]={-LINF, -LINF};
	for(auto a:e[x]) if(a.second!=par[x].second){
		par[a.second]=make_pair(a.first, x);
		dfs(a.second);
		psum+=P[a.second];
		lint t=D[a.second]-P[a.second]+a.first;
		mx[1]=max(t, mx[1]);
		if(mx[1]>mx[0]) swap(mx[0], mx[1]);
	}
	D[x]=psum;
	P[x]=max(D[x], psum+mx[0]+par[x].first);
}

int main(){
	lint N;
	lint a[MAXN], b[MAXN], c[MAXN];
	lint ans=0ll;

	scanf("%lld", &N);
	for(lint i=0; i<N-1; i++) scanf("%lld%lld%lld", a+i, b+i, c+i);

	for(lint i=0; i<N-1; i++){
		e[a[i]].push_back(make_pair(c[i], b[i]));
		e[b[i]].push_back(make_pair(c[i], a[i]));
	}
	for(int i=1; i<=N; i++){
		for(int j=1; j<=N; j++) par[j]=make_pair(0ll, 0ll);
		dfs(i);
		ans=max(ans, D[i]);
	}
	printf("%lld", ans);
	return 0;
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &N);
  ~~~~~^~~~~~~~~~~~
beads.cpp:37:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(lint i=0; i<N-1; i++) scanf("%lld%lld%lld", a+i, b+i, c+i);
                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4992 KB Output is correct
2 Correct 5 ms 4992 KB Output is correct
3 Correct 5 ms 4992 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 5 ms 5168 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 11 ms 5120 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5092 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4992 KB Output is correct
2 Correct 5 ms 4992 KB Output is correct
3 Correct 5 ms 4992 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 5 ms 5168 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 11 ms 5120 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5092 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5096 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5036 KB Output is correct
19 Correct 5 ms 4992 KB Output is correct
20 Correct 6 ms 5084 KB Output is correct
21 Correct 5 ms 5092 KB Output is correct
22 Correct 5 ms 5092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4992 KB Output is correct
2 Correct 5 ms 4992 KB Output is correct
3 Correct 5 ms 4992 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 5 ms 5168 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 11 ms 5120 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5092 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5096 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5036 KB Output is correct
19 Correct 5 ms 4992 KB Output is correct
20 Correct 6 ms 5084 KB Output is correct
21 Correct 5 ms 5092 KB Output is correct
22 Correct 5 ms 5092 KB Output is correct
23 Correct 934 ms 5616 KB Output is correct
24 Correct 907 ms 5612 KB Output is correct
25 Correct 937 ms 5616 KB Output is correct
26 Execution timed out 1065 ms 6144 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4992 KB Output is correct
2 Correct 5 ms 4992 KB Output is correct
3 Correct 5 ms 4992 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 5 ms 5168 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 11 ms 5120 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5092 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5096 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5036 KB Output is correct
19 Correct 5 ms 4992 KB Output is correct
20 Correct 6 ms 5084 KB Output is correct
21 Correct 5 ms 5092 KB Output is correct
22 Correct 5 ms 5092 KB Output is correct
23 Correct 934 ms 5616 KB Output is correct
24 Correct 907 ms 5612 KB Output is correct
25 Correct 937 ms 5616 KB Output is correct
26 Execution timed out 1065 ms 6144 KB Time limit exceeded
27 Halted 0 ms 0 KB -