답안 #391203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391203 2021-04-18T08:25:03 Z keta_tsimakuridze Power Plant (JOI20_power) C++14
100 / 100
291 ms 29660 KB
#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,ans,dp[N],u,v,n;
string s;
vector<int>V[N];
void dfs(int u,int p){
	if(s[u]=='1')  dp[u] = 1;
	int sum = 0, mx = 0;
	for(int i=0;i<V[u].size();i++){
		if(V[u][i] == p) continue;
		dfs(V[u][i],u); 
		sum+=dp[V[u][i]];
		mx=max(mx,dp[V[u][i]]);
	}
	ans = max(ans,max(mx+(s[u]=='1'), sum - (s[u]=='1')));
	dp[u] = max(dp[u], max(mx-(s[u]=='1'),sum-(s[u]=='1')));
}
 main(){
	// t=1;
	cin>>n;
	for(int i=2;i<=n;i++){
		cin>>u>>v;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	cin>>s;
	s='#'+s;
	dfs(1,0);
	cout<<ans;
}

Compilation message

power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:13:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i=0;i<V[u].size();i++){
      |              ~^~~~~~~~~~~~
power.cpp: At global scope:
power.cpp:22:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 |  main(){
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5072 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4996 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4940 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 3 ms 5000 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 3 ms 4908 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4996 KB Output is correct
17 Correct 3 ms 5044 KB Output is correct
18 Correct 4 ms 4944 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5072 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4996 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4940 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 3 ms 5000 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 3 ms 4908 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4996 KB Output is correct
17 Correct 3 ms 5044 KB Output is correct
18 Correct 4 ms 4944 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 5 ms 5084 KB Output is correct
23 Correct 5 ms 5016 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 5 ms 5124 KB Output is correct
27 Correct 5 ms 5076 KB Output is correct
28 Correct 6 ms 5016 KB Output is correct
29 Correct 5 ms 5204 KB Output is correct
30 Correct 5 ms 5204 KB Output is correct
31 Correct 5 ms 5068 KB Output is correct
32 Correct 5 ms 5076 KB Output is correct
33 Correct 5 ms 5012 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5020 KB Output is correct
37 Correct 5 ms 5068 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 5 ms 5076 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 5 ms 5076 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5068 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 5 ms 5068 KB Output is correct
48 Correct 5 ms 5076 KB Output is correct
49 Correct 5 ms 5156 KB Output is correct
50 Correct 5 ms 5068 KB Output is correct
51 Correct 5 ms 5064 KB Output is correct
52 Correct 5 ms 5068 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 5 ms 5068 KB Output is correct
56 Correct 5 ms 5020 KB Output is correct
57 Correct 5 ms 5196 KB Output is correct
58 Correct 5 ms 5068 KB Output is correct
59 Correct 5 ms 5128 KB Output is correct
60 Correct 5 ms 5068 KB Output is correct
61 Correct 5 ms 5016 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 5 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5072 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4996 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4940 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 3 ms 5000 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 3 ms 4908 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4996 KB Output is correct
17 Correct 3 ms 5044 KB Output is correct
18 Correct 4 ms 4944 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 5 ms 5084 KB Output is correct
23 Correct 5 ms 5016 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 5 ms 5124 KB Output is correct
27 Correct 5 ms 5076 KB Output is correct
28 Correct 6 ms 5016 KB Output is correct
29 Correct 5 ms 5204 KB Output is correct
30 Correct 5 ms 5204 KB Output is correct
31 Correct 5 ms 5068 KB Output is correct
32 Correct 5 ms 5076 KB Output is correct
33 Correct 5 ms 5012 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5020 KB Output is correct
37 Correct 5 ms 5068 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 5 ms 5076 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 5 ms 5076 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5068 KB Output is correct
46 Correct 5 ms 5068 KB Output is correct
47 Correct 5 ms 5068 KB Output is correct
48 Correct 5 ms 5076 KB Output is correct
49 Correct 5 ms 5156 KB Output is correct
50 Correct 5 ms 5068 KB Output is correct
51 Correct 5 ms 5064 KB Output is correct
52 Correct 5 ms 5068 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 5 ms 5068 KB Output is correct
56 Correct 5 ms 5020 KB Output is correct
57 Correct 5 ms 5196 KB Output is correct
58 Correct 5 ms 5068 KB Output is correct
59 Correct 5 ms 5128 KB Output is correct
60 Correct 5 ms 5068 KB Output is correct
61 Correct 5 ms 5016 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 5 ms 5068 KB Output is correct
64 Correct 239 ms 16916 KB Output is correct
65 Correct 243 ms 16916 KB Output is correct
66 Correct 243 ms 17028 KB Output is correct
67 Correct 245 ms 16948 KB Output is correct
68 Correct 239 ms 16944 KB Output is correct
69 Correct 262 ms 16940 KB Output is correct
70 Correct 240 ms 16832 KB Output is correct
71 Correct 244 ms 16848 KB Output is correct
72 Correct 242 ms 16868 KB Output is correct
73 Correct 266 ms 28584 KB Output is correct
74 Correct 291 ms 28488 KB Output is correct
75 Correct 244 ms 18068 KB Output is correct
76 Correct 239 ms 18064 KB Output is correct
77 Correct 255 ms 16912 KB Output is correct
78 Correct 250 ms 16820 KB Output is correct
79 Correct 243 ms 16916 KB Output is correct
80 Correct 250 ms 16912 KB Output is correct
81 Correct 222 ms 16972 KB Output is correct
82 Correct 267 ms 16976 KB Output is correct
83 Correct 263 ms 21984 KB Output is correct
84 Correct 258 ms 24112 KB Output is correct
85 Correct 274 ms 23880 KB Output is correct
86 Correct 238 ms 18292 KB Output is correct
87 Correct 245 ms 17680 KB Output is correct
88 Correct 255 ms 17700 KB Output is correct
89 Correct 237 ms 17780 KB Output is correct
90 Correct 237 ms 17612 KB Output is correct
91 Correct 232 ms 17824 KB Output is correct
92 Correct 235 ms 18104 KB Output is correct
93 Correct 248 ms 20408 KB Output is correct
94 Correct 252 ms 22024 KB Output is correct
95 Correct 235 ms 20788 KB Output is correct
96 Correct 240 ms 19048 KB Output is correct
97 Correct 252 ms 17452 KB Output is correct
98 Correct 226 ms 17080 KB Output is correct
99 Correct 243 ms 17116 KB Output is correct
100 Correct 238 ms 19936 KB Output is correct
101 Correct 239 ms 17804 KB Output is correct
102 Correct 240 ms 17200 KB Output is correct
103 Correct 234 ms 17172 KB Output is correct
104 Correct 197 ms 17624 KB Output is correct
105 Correct 263 ms 25292 KB Output is correct
106 Correct 181 ms 17368 KB Output is correct
107 Correct 176 ms 17332 KB Output is correct
108 Correct 273 ms 29400 KB Output is correct
109 Correct 193 ms 17584 KB Output is correct
110 Correct 267 ms 29660 KB Output is correct
111 Correct 231 ms 16984 KB Output is correct