Submission #423332

# Submission time Handle Problem Language Result Execution time Memory
423332 2021-06-11T01:29:06 Z DanerZein Power Plant (JOI20_power) C++14
47 / 100
1500 ms 14432 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vector<vi> G;
string x;
int dfs(int u,int p){
  int ans=0;
  for(auto &v:G[u]){
    if(v!=p){
      ans+=dfs(v,u);
    }
  }
  int mi=0;
  if(x[u]=='1') mi=1; 
  return max(ans-mi,mi);
}
int main(){
  int n;
  cin>>n;
  G.resize(n+1);
  for(int i=0;i<n-1;i++){
    int a,b; cin>>a>>b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin>>x;
  int c=0;
  for(int i=0;i<x.size();i++){
    if(x[i]=='1') c++;
  }
  int ans=min(c,2);
  for(int i=0;i<n;i++){
    int rp=dfs(i,-1);
    ans=max(ans,rp);
  }
  cout<<ans<<endl;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i=0;i<x.size();i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 272 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 272 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 67 ms 332 KB Output is correct
23 Correct 67 ms 332 KB Output is correct
24 Correct 70 ms 332 KB Output is correct
25 Correct 70 ms 332 KB Output is correct
26 Correct 67 ms 408 KB Output is correct
27 Correct 66 ms 400 KB Output is correct
28 Correct 66 ms 332 KB Output is correct
29 Correct 87 ms 524 KB Output is correct
30 Correct 86 ms 460 KB Output is correct
31 Correct 59 ms 404 KB Output is correct
32 Correct 60 ms 332 KB Output is correct
33 Correct 65 ms 400 KB Output is correct
34 Correct 68 ms 332 KB Output is correct
35 Correct 70 ms 404 KB Output is correct
36 Correct 70 ms 332 KB Output is correct
37 Correct 56 ms 332 KB Output is correct
38 Correct 63 ms 300 KB Output is correct
39 Correct 73 ms 460 KB Output is correct
40 Correct 77 ms 460 KB Output is correct
41 Correct 81 ms 460 KB Output is correct
42 Correct 71 ms 332 KB Output is correct
43 Correct 72 ms 432 KB Output is correct
44 Correct 75 ms 332 KB Output is correct
45 Correct 61 ms 332 KB Output is correct
46 Correct 60 ms 436 KB Output is correct
47 Correct 60 ms 432 KB Output is correct
48 Correct 54 ms 468 KB Output is correct
49 Correct 57 ms 460 KB Output is correct
50 Correct 56 ms 460 KB Output is correct
51 Correct 67 ms 332 KB Output is correct
52 Correct 64 ms 412 KB Output is correct
53 Correct 58 ms 460 KB Output is correct
54 Correct 57 ms 332 KB Output is correct
55 Correct 65 ms 332 KB Output is correct
56 Correct 28 ms 332 KB Output is correct
57 Correct 86 ms 520 KB Output is correct
58 Correct 28 ms 412 KB Output is correct
59 Correct 27 ms 332 KB Output is correct
60 Correct 85 ms 580 KB Output is correct
61 Correct 28 ms 332 KB Output is correct
62 Correct 85 ms 524 KB Output is correct
63 Correct 50 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 272 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 67 ms 332 KB Output is correct
23 Correct 67 ms 332 KB Output is correct
24 Correct 70 ms 332 KB Output is correct
25 Correct 70 ms 332 KB Output is correct
26 Correct 67 ms 408 KB Output is correct
27 Correct 66 ms 400 KB Output is correct
28 Correct 66 ms 332 KB Output is correct
29 Correct 87 ms 524 KB Output is correct
30 Correct 86 ms 460 KB Output is correct
31 Correct 59 ms 404 KB Output is correct
32 Correct 60 ms 332 KB Output is correct
33 Correct 65 ms 400 KB Output is correct
34 Correct 68 ms 332 KB Output is correct
35 Correct 70 ms 404 KB Output is correct
36 Correct 70 ms 332 KB Output is correct
37 Correct 56 ms 332 KB Output is correct
38 Correct 63 ms 300 KB Output is correct
39 Correct 73 ms 460 KB Output is correct
40 Correct 77 ms 460 KB Output is correct
41 Correct 81 ms 460 KB Output is correct
42 Correct 71 ms 332 KB Output is correct
43 Correct 72 ms 432 KB Output is correct
44 Correct 75 ms 332 KB Output is correct
45 Correct 61 ms 332 KB Output is correct
46 Correct 60 ms 436 KB Output is correct
47 Correct 60 ms 432 KB Output is correct
48 Correct 54 ms 468 KB Output is correct
49 Correct 57 ms 460 KB Output is correct
50 Correct 56 ms 460 KB Output is correct
51 Correct 67 ms 332 KB Output is correct
52 Correct 64 ms 412 KB Output is correct
53 Correct 58 ms 460 KB Output is correct
54 Correct 57 ms 332 KB Output is correct
55 Correct 65 ms 332 KB Output is correct
56 Correct 28 ms 332 KB Output is correct
57 Correct 86 ms 520 KB Output is correct
58 Correct 28 ms 412 KB Output is correct
59 Correct 27 ms 332 KB Output is correct
60 Correct 85 ms 580 KB Output is correct
61 Correct 28 ms 332 KB Output is correct
62 Correct 85 ms 524 KB Output is correct
63 Correct 50 ms 332 KB Output is correct
64 Execution timed out 1604 ms 14432 KB Time limit exceeded
65 Halted 0 ms 0 KB -