답안 #507659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
507659 2022-01-12T22:58:34 Z nichke Power Plant (JOI20_power) C++14
100 / 100
155 ms 29696 KB
// I may fail a thousand times
// But there is no giving up
// IOI - here I come
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
int ans;
string s;
int dp[(int)2e5+5];
vector<int> g[(int)2e5+5];
int dfs(int v,int p){
	for(int u:g[v]){
		if(u==p)continue;
		dp[v]+=dfs(u,v);
		ans=max(ans,dp[u]+(s[v-1]=='1'));
	}
	dp[v]-=s[v-1]=='1';
	dp[v]=max(dp[v],(int)(s[v-1]=='1'));
	ans=max(ans,dp[v]);
	return dp[v];
}
signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
	int n;cin>>n;
	for(int i=1,u,v;i<n;i++)cin>>u>>v,g[u].pb(v),g[v].pb(u);
  cin>>s;
	dfs(1,1);
	cout<<ans<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5020 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 5000 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 ms 5020 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5020 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 5000 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 ms 5020 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5000 KB Output is correct
22 Correct 3 ms 5032 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 3 ms 5028 KB Output is correct
27 Correct 3 ms 5084 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
29 Correct 3 ms 5196 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 4 ms 5028 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 3 ms 5060 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 4 ms 5084 KB Output is correct
42 Correct 4 ms 5024 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 3 ms 5160 KB Output is correct
45 Correct 3 ms 5160 KB Output is correct
46 Correct 3 ms 5064 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 4 ms 5164 KB Output is correct
49 Correct 3 ms 5072 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 3 ms 5080 KB Output is correct
53 Correct 3 ms 5156 KB Output is correct
54 Correct 4 ms 5160 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5028 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 4 ms 5164 KB Output is correct
61 Correct 3 ms 5020 KB Output is correct
62 Correct 3 ms 5152 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5020 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 5000 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 ms 5020 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5000 KB Output is correct
22 Correct 3 ms 5032 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 3 ms 5028 KB Output is correct
27 Correct 3 ms 5084 KB Output is correct
28 Correct 3 ms 5032 KB Output is correct
29 Correct 3 ms 5196 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 4 ms 5028 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 3 ms 5060 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 4 ms 5084 KB Output is correct
42 Correct 4 ms 5024 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 3 ms 5160 KB Output is correct
45 Correct 3 ms 5160 KB Output is correct
46 Correct 3 ms 5064 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 4 ms 5164 KB Output is correct
49 Correct 3 ms 5072 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 3 ms 5080 KB Output is correct
53 Correct 3 ms 5156 KB Output is correct
54 Correct 4 ms 5160 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5028 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 4 ms 5164 KB Output is correct
61 Correct 3 ms 5020 KB Output is correct
62 Correct 3 ms 5152 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 123 ms 16824 KB Output is correct
65 Correct 119 ms 16868 KB Output is correct
66 Correct 130 ms 16884 KB Output is correct
67 Correct 110 ms 16904 KB Output is correct
68 Correct 128 ms 16848 KB Output is correct
69 Correct 123 ms 16876 KB Output is correct
70 Correct 127 ms 16948 KB Output is correct
71 Correct 119 ms 16872 KB Output is correct
72 Correct 122 ms 16952 KB Output is correct
73 Correct 140 ms 28548 KB Output is correct
74 Correct 122 ms 28508 KB Output is correct
75 Correct 114 ms 18112 KB Output is correct
76 Correct 125 ms 18124 KB Output is correct
77 Correct 130 ms 16904 KB Output is correct
78 Correct 125 ms 16932 KB Output is correct
79 Correct 114 ms 16940 KB Output is correct
80 Correct 128 ms 16852 KB Output is correct
81 Correct 123 ms 17004 KB Output is correct
82 Correct 100 ms 16956 KB Output is correct
83 Correct 155 ms 22000 KB Output is correct
84 Correct 122 ms 24076 KB Output is correct
85 Correct 121 ms 23824 KB Output is correct
86 Correct 143 ms 18308 KB Output is correct
87 Correct 123 ms 17660 KB Output is correct
88 Correct 117 ms 17820 KB Output is correct
89 Correct 119 ms 17756 KB Output is correct
90 Correct 143 ms 17580 KB Output is correct
91 Correct 108 ms 17768 KB Output is correct
92 Correct 116 ms 18184 KB Output is correct
93 Correct 105 ms 20372 KB Output is correct
94 Correct 107 ms 22084 KB Output is correct
95 Correct 109 ms 20828 KB Output is correct
96 Correct 112 ms 18988 KB Output is correct
97 Correct 112 ms 17428 KB Output is correct
98 Correct 142 ms 17204 KB Output is correct
99 Correct 111 ms 17080 KB Output is correct
100 Correct 103 ms 19952 KB Output is correct
101 Correct 110 ms 17812 KB Output is correct
102 Correct 107 ms 17368 KB Output is correct
103 Correct 113 ms 17188 KB Output is correct
104 Correct 75 ms 17588 KB Output is correct
105 Correct 127 ms 25404 KB Output is correct
106 Correct 78 ms 17440 KB Output is correct
107 Correct 80 ms 17384 KB Output is correct
108 Correct 121 ms 29332 KB Output is correct
109 Correct 69 ms 17580 KB Output is correct
110 Correct 139 ms 29696 KB Output is correct
111 Correct 108 ms 16812 KB Output is correct