Submission #534909

# Submission time Handle Problem Language Result Execution time Memory
534909 2022-03-09T06:23:03 Z farhan132 Power Plant (JOI20_power) C++17
100 / 100
192 ms 33968 KB
/***Farhan132***/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>



using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm; 
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctz(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)

const ll mod =  (ll) 998244353;
const ll maxn = (ll)2e5 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
//const ll INF = (ll)1e18;
 
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

bool USACO = 0;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<ll, null_type,less< ll >, rb_tree_tag,tree_order_statistics_node_update>

const ll N = 5e5 + 5;

string s;
vector < ll > v[N];

ll res = 0;

ll dp(ll node, ll p){
  ll ans = 0, mx = 0;
  for(auto u : v[node]){
    if(u - p){
      ll k = dp(u, node);
      ans += k;
      mx = max(mx, k);
    }
  }
  ll k = (s[node] == '1');
  res = max({res , mx + k , ans - k});
  ans = max(k , ans - k);
  return ans; 
}

void solve(){

    ll n; cin >> n;

    for(ll i = 1; i < n; i++){
      ll x , y; cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
    }

    cin >> s;
    s = '1' + s;

    for(ll i = 1; i <= n; i++){
      if(v[i].size() <= 1){
        dp(i, 0);
        break;
      }
    }

    cout << res << '\n';

   return;
}

 
int main() {
    
    
    #ifdef LOCAL
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
    #else 
       ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
      
    #endif
    //pre(N);
    
    ll T = 1;
    //cin >> T;
    ll CT = 0;
    while(T--){
      //  cout << "Case #" << ++CT <<": " ;
        solve();
    }
 
    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:125:8: warning: unused variable 'CT' [-Wunused-variable]
  125 |     ll CT = 0;
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 12056 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12072 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 7 ms 12060 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 11980 KB Output is correct
16 Correct 7 ms 12108 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 12056 KB Output is correct
20 Correct 6 ms 11980 KB Output is correct
21 Correct 7 ms 12056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 12056 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12072 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 7 ms 12060 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 11980 KB Output is correct
16 Correct 7 ms 12108 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 12056 KB Output is correct
20 Correct 6 ms 11980 KB Output is correct
21 Correct 7 ms 12056 KB Output is correct
22 Correct 8 ms 12072 KB Output is correct
23 Correct 8 ms 12064 KB Output is correct
24 Correct 8 ms 12072 KB Output is correct
25 Correct 8 ms 12072 KB Output is correct
26 Correct 8 ms 12128 KB Output is correct
27 Correct 8 ms 12124 KB Output is correct
28 Correct 8 ms 12108 KB Output is correct
29 Correct 7 ms 12200 KB Output is correct
30 Correct 8 ms 12236 KB Output is correct
31 Correct 7 ms 12108 KB Output is correct
32 Correct 7 ms 12084 KB Output is correct
33 Correct 7 ms 12108 KB Output is correct
34 Correct 7 ms 12068 KB Output is correct
35 Correct 8 ms 12108 KB Output is correct
36 Correct 7 ms 12108 KB Output is correct
37 Correct 8 ms 12068 KB Output is correct
38 Correct 7 ms 12068 KB Output is correct
39 Correct 11 ms 12072 KB Output is correct
40 Correct 8 ms 12108 KB Output is correct
41 Correct 8 ms 12108 KB Output is correct
42 Correct 8 ms 12108 KB Output is correct
43 Correct 9 ms 12108 KB Output is correct
44 Correct 8 ms 12108 KB Output is correct
45 Correct 7 ms 12108 KB Output is correct
46 Correct 7 ms 12108 KB Output is correct
47 Correct 8 ms 12068 KB Output is correct
48 Correct 8 ms 12196 KB Output is correct
49 Correct 7 ms 12204 KB Output is correct
50 Correct 7 ms 12108 KB Output is correct
51 Correct 7 ms 12108 KB Output is correct
52 Correct 7 ms 12108 KB Output is correct
53 Correct 8 ms 12124 KB Output is correct
54 Correct 8 ms 12072 KB Output is correct
55 Correct 7 ms 12072 KB Output is correct
56 Correct 7 ms 12108 KB Output is correct
57 Correct 8 ms 12244 KB Output is correct
58 Correct 8 ms 12120 KB Output is correct
59 Correct 8 ms 12108 KB Output is correct
60 Correct 7 ms 12236 KB Output is correct
61 Correct 7 ms 12108 KB Output is correct
62 Correct 7 ms 12236 KB Output is correct
63 Correct 7 ms 12096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 12056 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12072 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 7 ms 12060 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 11980 KB Output is correct
16 Correct 7 ms 12108 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 12056 KB Output is correct
20 Correct 6 ms 11980 KB Output is correct
21 Correct 7 ms 12056 KB Output is correct
22 Correct 8 ms 12072 KB Output is correct
23 Correct 8 ms 12064 KB Output is correct
24 Correct 8 ms 12072 KB Output is correct
25 Correct 8 ms 12072 KB Output is correct
26 Correct 8 ms 12128 KB Output is correct
27 Correct 8 ms 12124 KB Output is correct
28 Correct 8 ms 12108 KB Output is correct
29 Correct 7 ms 12200 KB Output is correct
30 Correct 8 ms 12236 KB Output is correct
31 Correct 7 ms 12108 KB Output is correct
32 Correct 7 ms 12084 KB Output is correct
33 Correct 7 ms 12108 KB Output is correct
34 Correct 7 ms 12068 KB Output is correct
35 Correct 8 ms 12108 KB Output is correct
36 Correct 7 ms 12108 KB Output is correct
37 Correct 8 ms 12068 KB Output is correct
38 Correct 7 ms 12068 KB Output is correct
39 Correct 11 ms 12072 KB Output is correct
40 Correct 8 ms 12108 KB Output is correct
41 Correct 8 ms 12108 KB Output is correct
42 Correct 8 ms 12108 KB Output is correct
43 Correct 9 ms 12108 KB Output is correct
44 Correct 8 ms 12108 KB Output is correct
45 Correct 7 ms 12108 KB Output is correct
46 Correct 7 ms 12108 KB Output is correct
47 Correct 8 ms 12068 KB Output is correct
48 Correct 8 ms 12196 KB Output is correct
49 Correct 7 ms 12204 KB Output is correct
50 Correct 7 ms 12108 KB Output is correct
51 Correct 7 ms 12108 KB Output is correct
52 Correct 7 ms 12108 KB Output is correct
53 Correct 8 ms 12124 KB Output is correct
54 Correct 8 ms 12072 KB Output is correct
55 Correct 7 ms 12072 KB Output is correct
56 Correct 7 ms 12108 KB Output is correct
57 Correct 8 ms 12244 KB Output is correct
58 Correct 8 ms 12120 KB Output is correct
59 Correct 8 ms 12108 KB Output is correct
60 Correct 7 ms 12236 KB Output is correct
61 Correct 7 ms 12108 KB Output is correct
62 Correct 7 ms 12236 KB Output is correct
63 Correct 7 ms 12096 KB Output is correct
64 Correct 131 ms 22536 KB Output is correct
65 Correct 192 ms 22660 KB Output is correct
66 Correct 125 ms 22636 KB Output is correct
67 Correct 134 ms 22520 KB Output is correct
68 Correct 130 ms 22564 KB Output is correct
69 Correct 152 ms 22560 KB Output is correct
70 Correct 130 ms 22696 KB Output is correct
71 Correct 147 ms 22532 KB Output is correct
72 Correct 122 ms 22660 KB Output is correct
73 Correct 150 ms 33872 KB Output is correct
74 Correct 189 ms 33816 KB Output is correct
75 Correct 132 ms 23776 KB Output is correct
76 Correct 135 ms 23816 KB Output is correct
77 Correct 125 ms 22552 KB Output is correct
78 Correct 146 ms 22528 KB Output is correct
79 Correct 157 ms 22612 KB Output is correct
80 Correct 118 ms 22536 KB Output is correct
81 Correct 122 ms 22500 KB Output is correct
82 Correct 186 ms 22368 KB Output is correct
83 Correct 136 ms 26408 KB Output is correct
84 Correct 147 ms 25788 KB Output is correct
85 Correct 137 ms 26876 KB Output is correct
86 Correct 124 ms 23432 KB Output is correct
87 Correct 155 ms 22972 KB Output is correct
88 Correct 117 ms 23072 KB Output is correct
89 Correct 112 ms 23116 KB Output is correct
90 Correct 132 ms 22960 KB Output is correct
91 Correct 153 ms 23176 KB Output is correct
92 Correct 112 ms 23404 KB Output is correct
93 Correct 119 ms 27972 KB Output is correct
94 Correct 143 ms 28396 KB Output is correct
95 Correct 119 ms 26864 KB Output is correct
96 Correct 118 ms 24032 KB Output is correct
97 Correct 134 ms 22792 KB Output is correct
98 Correct 116 ms 22692 KB Output is correct
99 Correct 122 ms 22644 KB Output is correct
100 Correct 117 ms 24812 KB Output is correct
101 Correct 126 ms 22980 KB Output is correct
102 Correct 105 ms 22636 KB Output is correct
103 Correct 136 ms 22764 KB Output is correct
104 Correct 83 ms 23156 KB Output is correct
105 Correct 143 ms 33968 KB Output is correct
106 Correct 83 ms 22924 KB Output is correct
107 Correct 74 ms 22932 KB Output is correct
108 Correct 161 ms 33856 KB Output is correct
109 Correct 89 ms 23028 KB Output is correct
110 Correct 155 ms 33768 KB Output is correct
111 Correct 110 ms 22556 KB Output is correct