Submission #317228

# Submission time Handle Problem Language Result Execution time Memory
317228 2020-10-29T06:40:43 Z tasfiq4 Power Plant (JOI20_power) C++14
100 / 100
198 ms 26204 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int > pii;
typedef long long int lld;
#define pi acos(-1)
#define fr(i,m,n) for(i=m;i<n;i++)
#define fu(i,m,n) for(i=m;i>=n;i--)
#define vec vector<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define mom(ara) memset(ara,0,sizeof(ara));
#define m1m(ara) memset(ara,-1,sizeof(ara));
#define endl "\n"
#define eps 1.19209e-07
vec adj[200010];
int val[200010],dp[200010],ans=0;
void dfs(int u ,int p)
{
	int sum=0,mx=0;
	for(auto v:adj[u])
	{
		if(v==p) continue;
		dfs(v,u);
		sum+=dp[v];
		mx=max(mx,dp[v]);
	}	
	if(val[u]) ans=max(ans,max(mx+1,sum-1));
	else ans=max(ans,sum);
	if(val[u]) dp[u]=max(1,sum-1);
    else dp[u]=sum;
}
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int i,j,k,a,b,c,x,y,z,n,m,t;
    cin>>n;
    string s;
    fr(i,1,n){
    	cin>>a>>b;
    	adj[a].pb(b);
    	adj[b].pb(a);
    }
    getline(cin,s);
    cin>>s;
    fr(i,0,s.size())
    {
    	if(s[i]=='1') val[i+1]=1;
    }
    dfs(1,0);
    cout<<ans<<endl;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:6:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define fr(i,m,n) for(i=m;i<n;i++)
......
   47 |     fr(i,0,s.size())
      |        ~~~~~~~~~~~~         
power.cpp:47:5: note: in expansion of macro 'fr'
   47 |     fr(i,0,s.size())
      |     ^~
power.cpp:37:11: warning: unused variable 'j' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |           ^
power.cpp:37:13: warning: unused variable 'k' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |             ^
power.cpp:37:19: warning: unused variable 'c' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |                   ^
power.cpp:37:21: warning: unused variable 'x' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |                     ^
power.cpp:37:23: warning: unused variable 'y' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |                       ^
power.cpp:37:25: warning: unused variable 'z' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |                         ^
power.cpp:37:29: warning: unused variable 'm' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |                             ^
power.cpp:37:31: warning: unused variable 't' [-Wunused-variable]
   37 |     int i,j,k,a,b,c,x,y,z,n,m,t;
      |                               ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5120 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 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5120 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 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 4 ms 5120 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5120 KB Output is correct
40 Correct 5 ms 5120 KB Output is correct
41 Correct 4 ms 5120 KB Output is correct
42 Correct 5 ms 5152 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 4 ms 5120 KB Output is correct
47 Correct 5 ms 5120 KB Output is correct
48 Correct 5 ms 5248 KB Output is correct
49 Correct 4 ms 5248 KB Output is correct
50 Correct 4 ms 5120 KB Output is correct
51 Correct 4 ms 5120 KB Output is correct
52 Correct 4 ms 5120 KB Output is correct
53 Correct 4 ms 5120 KB Output is correct
54 Correct 4 ms 5120 KB Output is correct
55 Correct 4 ms 5120 KB Output is correct
56 Correct 4 ms 5120 KB Output is correct
57 Correct 5 ms 5248 KB Output is correct
58 Correct 4 ms 5120 KB Output is correct
59 Correct 4 ms 5152 KB Output is correct
60 Correct 5 ms 5120 KB Output is correct
61 Correct 4 ms 5248 KB Output is correct
62 Correct 4 ms 5248 KB Output is correct
63 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5120 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 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 4 ms 5120 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5120 KB Output is correct
40 Correct 5 ms 5120 KB Output is correct
41 Correct 4 ms 5120 KB Output is correct
42 Correct 5 ms 5152 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 4 ms 5120 KB Output is correct
47 Correct 5 ms 5120 KB Output is correct
48 Correct 5 ms 5248 KB Output is correct
49 Correct 4 ms 5248 KB Output is correct
50 Correct 4 ms 5120 KB Output is correct
51 Correct 4 ms 5120 KB Output is correct
52 Correct 4 ms 5120 KB Output is correct
53 Correct 4 ms 5120 KB Output is correct
54 Correct 4 ms 5120 KB Output is correct
55 Correct 4 ms 5120 KB Output is correct
56 Correct 4 ms 5120 KB Output is correct
57 Correct 5 ms 5248 KB Output is correct
58 Correct 4 ms 5120 KB Output is correct
59 Correct 4 ms 5152 KB Output is correct
60 Correct 5 ms 5120 KB Output is correct
61 Correct 4 ms 5248 KB Output is correct
62 Correct 4 ms 5248 KB Output is correct
63 Correct 4 ms 5120 KB Output is correct
64 Correct 172 ms 13340 KB Output is correct
65 Correct 174 ms 13496 KB Output is correct
66 Correct 174 ms 13348 KB Output is correct
67 Correct 168 ms 13240 KB Output is correct
68 Correct 166 ms 13348 KB Output is correct
69 Correct 173 ms 13276 KB Output is correct
70 Correct 163 ms 13252 KB Output is correct
71 Correct 169 ms 13252 KB Output is correct
72 Correct 163 ms 12560 KB Output is correct
73 Correct 198 ms 25912 KB Output is correct
74 Correct 198 ms 25788 KB Output is correct
75 Correct 170 ms 13112 KB Output is correct
76 Correct 174 ms 13124 KB Output is correct
77 Correct 173 ms 13364 KB Output is correct
78 Correct 176 ms 13244 KB Output is correct
79 Correct 183 ms 13200 KB Output is correct
80 Correct 167 ms 13240 KB Output is correct
81 Correct 145 ms 13680 KB Output is correct
82 Correct 157 ms 13432 KB Output is correct
83 Correct 177 ms 18400 KB Output is correct
84 Correct 184 ms 20552 KB Output is correct
85 Correct 183 ms 20292 KB Output is correct
86 Correct 167 ms 14648 KB Output is correct
87 Correct 167 ms 14004 KB Output is correct
88 Correct 164 ms 14580 KB Output is correct
89 Correct 168 ms 14536 KB Output is correct
90 Correct 161 ms 14340 KB Output is correct
91 Correct 165 ms 14492 KB Output is correct
92 Correct 172 ms 14888 KB Output is correct
93 Correct 156 ms 17412 KB Output is correct
94 Correct 146 ms 19056 KB Output is correct
95 Correct 150 ms 17776 KB Output is correct
96 Correct 164 ms 16036 KB Output is correct
97 Correct 168 ms 14380 KB Output is correct
98 Correct 153 ms 14056 KB Output is correct
99 Correct 159 ms 13620 KB Output is correct
100 Correct 156 ms 16804 KB Output is correct
101 Correct 161 ms 14772 KB Output is correct
102 Correct 151 ms 14084 KB Output is correct
103 Correct 159 ms 13872 KB Output is correct
104 Correct 97 ms 13288 KB Output is correct
105 Correct 185 ms 22072 KB Output is correct
106 Correct 95 ms 14192 KB Output is correct
107 Correct 103 ms 14188 KB Output is correct
108 Correct 192 ms 25912 KB Output is correct
109 Correct 101 ms 13288 KB Output is correct
110 Correct 185 ms 26204 KB Output is correct
111 Correct 161 ms 13128 KB Output is correct