답안 #412441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412441 2021-05-26T22:06:54 Z CSQ31 Power Plant (JOI20_power) C++14
100 / 100
183 ms 29652 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e8)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5+5;
ll ans = 0;
vector<ll>dp(MAXN);
vii adj(MAXN);
string s;
void dfs(int v,int u){
	dp[v] = (s[v]=='1');
	ll mx = 0,sum =0;
	for(int x:adj[v]){
		if(x == u)continue;
		dfs(x,v);
		mx = max(mx,dp[x]);
		sum+=dp[x];
	}
	if(s[v] == '1')ans = max(ans,mx+1);
	dp[v] = max(dp[v],sum-dp[v]);
	ans = max(ans,dp[v]);
}
int main()
{
	owo
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int v,u;
		cin>>v>>u;
		v--;
		u--;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	cin>>s;
	dfs(0,-1);
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 4 ms 6476 KB Output is correct
3 Correct 4 ms 6476 KB Output is correct
4 Correct 4 ms 6584 KB Output is correct
5 Correct 4 ms 6592 KB Output is correct
6 Correct 4 ms 6476 KB Output is correct
7 Correct 4 ms 6588 KB Output is correct
8 Correct 5 ms 6584 KB Output is correct
9 Correct 4 ms 6588 KB Output is correct
10 Correct 4 ms 6560 KB Output is correct
11 Correct 4 ms 6476 KB Output is correct
12 Correct 4 ms 6476 KB Output is correct
13 Correct 4 ms 6476 KB Output is correct
14 Correct 4 ms 6476 KB Output is correct
15 Correct 4 ms 6476 KB Output is correct
16 Correct 4 ms 6476 KB Output is correct
17 Correct 4 ms 6476 KB Output is correct
18 Correct 4 ms 6592 KB Output is correct
19 Correct 4 ms 6540 KB Output is correct
20 Correct 4 ms 6476 KB Output is correct
21 Correct 4 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 4 ms 6476 KB Output is correct
3 Correct 4 ms 6476 KB Output is correct
4 Correct 4 ms 6584 KB Output is correct
5 Correct 4 ms 6592 KB Output is correct
6 Correct 4 ms 6476 KB Output is correct
7 Correct 4 ms 6588 KB Output is correct
8 Correct 5 ms 6584 KB Output is correct
9 Correct 4 ms 6588 KB Output is correct
10 Correct 4 ms 6560 KB Output is correct
11 Correct 4 ms 6476 KB Output is correct
12 Correct 4 ms 6476 KB Output is correct
13 Correct 4 ms 6476 KB Output is correct
14 Correct 4 ms 6476 KB Output is correct
15 Correct 4 ms 6476 KB Output is correct
16 Correct 4 ms 6476 KB Output is correct
17 Correct 4 ms 6476 KB Output is correct
18 Correct 4 ms 6592 KB Output is correct
19 Correct 4 ms 6540 KB Output is correct
20 Correct 4 ms 6476 KB Output is correct
21 Correct 4 ms 6476 KB Output is correct
22 Correct 5 ms 6604 KB Output is correct
23 Correct 5 ms 6604 KB Output is correct
24 Correct 5 ms 6604 KB Output is correct
25 Correct 5 ms 6600 KB Output is correct
26 Correct 5 ms 6604 KB Output is correct
27 Correct 5 ms 6604 KB Output is correct
28 Correct 5 ms 6604 KB Output is correct
29 Correct 5 ms 6732 KB Output is correct
30 Correct 5 ms 6732 KB Output is correct
31 Correct 5 ms 6604 KB Output is correct
32 Correct 5 ms 6604 KB Output is correct
33 Correct 5 ms 6604 KB Output is correct
34 Correct 5 ms 6604 KB Output is correct
35 Correct 5 ms 6604 KB Output is correct
36 Correct 5 ms 6596 KB Output is correct
37 Correct 5 ms 6604 KB Output is correct
38 Correct 5 ms 6604 KB Output is correct
39 Correct 5 ms 6732 KB Output is correct
40 Correct 6 ms 6604 KB Output is correct
41 Correct 5 ms 6796 KB Output is correct
42 Correct 5 ms 6604 KB Output is correct
43 Correct 5 ms 6596 KB Output is correct
44 Correct 5 ms 6604 KB Output is correct
45 Correct 5 ms 6604 KB Output is correct
46 Correct 5 ms 6604 KB Output is correct
47 Correct 5 ms 6596 KB Output is correct
48 Correct 5 ms 6732 KB Output is correct
49 Correct 5 ms 6700 KB Output is correct
50 Correct 5 ms 6604 KB Output is correct
51 Correct 5 ms 6604 KB Output is correct
52 Correct 5 ms 6648 KB Output is correct
53 Correct 5 ms 6600 KB Output is correct
54 Correct 5 ms 6680 KB Output is correct
55 Correct 5 ms 6604 KB Output is correct
56 Correct 5 ms 6604 KB Output is correct
57 Correct 5 ms 6728 KB Output is correct
58 Correct 5 ms 6604 KB Output is correct
59 Correct 5 ms 6604 KB Output is correct
60 Correct 5 ms 6732 KB Output is correct
61 Correct 5 ms 6604 KB Output is correct
62 Correct 5 ms 6732 KB Output is correct
63 Correct 5 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 4 ms 6476 KB Output is correct
3 Correct 4 ms 6476 KB Output is correct
4 Correct 4 ms 6584 KB Output is correct
5 Correct 4 ms 6592 KB Output is correct
6 Correct 4 ms 6476 KB Output is correct
7 Correct 4 ms 6588 KB Output is correct
8 Correct 5 ms 6584 KB Output is correct
9 Correct 4 ms 6588 KB Output is correct
10 Correct 4 ms 6560 KB Output is correct
11 Correct 4 ms 6476 KB Output is correct
12 Correct 4 ms 6476 KB Output is correct
13 Correct 4 ms 6476 KB Output is correct
14 Correct 4 ms 6476 KB Output is correct
15 Correct 4 ms 6476 KB Output is correct
16 Correct 4 ms 6476 KB Output is correct
17 Correct 4 ms 6476 KB Output is correct
18 Correct 4 ms 6592 KB Output is correct
19 Correct 4 ms 6540 KB Output is correct
20 Correct 4 ms 6476 KB Output is correct
21 Correct 4 ms 6476 KB Output is correct
22 Correct 5 ms 6604 KB Output is correct
23 Correct 5 ms 6604 KB Output is correct
24 Correct 5 ms 6604 KB Output is correct
25 Correct 5 ms 6600 KB Output is correct
26 Correct 5 ms 6604 KB Output is correct
27 Correct 5 ms 6604 KB Output is correct
28 Correct 5 ms 6604 KB Output is correct
29 Correct 5 ms 6732 KB Output is correct
30 Correct 5 ms 6732 KB Output is correct
31 Correct 5 ms 6604 KB Output is correct
32 Correct 5 ms 6604 KB Output is correct
33 Correct 5 ms 6604 KB Output is correct
34 Correct 5 ms 6604 KB Output is correct
35 Correct 5 ms 6604 KB Output is correct
36 Correct 5 ms 6596 KB Output is correct
37 Correct 5 ms 6604 KB Output is correct
38 Correct 5 ms 6604 KB Output is correct
39 Correct 5 ms 6732 KB Output is correct
40 Correct 6 ms 6604 KB Output is correct
41 Correct 5 ms 6796 KB Output is correct
42 Correct 5 ms 6604 KB Output is correct
43 Correct 5 ms 6596 KB Output is correct
44 Correct 5 ms 6604 KB Output is correct
45 Correct 5 ms 6604 KB Output is correct
46 Correct 5 ms 6604 KB Output is correct
47 Correct 5 ms 6596 KB Output is correct
48 Correct 5 ms 6732 KB Output is correct
49 Correct 5 ms 6700 KB Output is correct
50 Correct 5 ms 6604 KB Output is correct
51 Correct 5 ms 6604 KB Output is correct
52 Correct 5 ms 6648 KB Output is correct
53 Correct 5 ms 6600 KB Output is correct
54 Correct 5 ms 6680 KB Output is correct
55 Correct 5 ms 6604 KB Output is correct
56 Correct 5 ms 6604 KB Output is correct
57 Correct 5 ms 6728 KB Output is correct
58 Correct 5 ms 6604 KB Output is correct
59 Correct 5 ms 6604 KB Output is correct
60 Correct 5 ms 6732 KB Output is correct
61 Correct 5 ms 6604 KB Output is correct
62 Correct 5 ms 6732 KB Output is correct
63 Correct 5 ms 6604 KB Output is correct
64 Correct 146 ms 16076 KB Output is correct
65 Correct 146 ms 15988 KB Output is correct
66 Correct 148 ms 16120 KB Output is correct
67 Correct 162 ms 16080 KB Output is correct
68 Correct 146 ms 16108 KB Output is correct
69 Correct 141 ms 15984 KB Output is correct
70 Correct 167 ms 16056 KB Output is correct
71 Correct 156 ms 15976 KB Output is correct
72 Correct 147 ms 16036 KB Output is correct
73 Correct 162 ms 28556 KB Output is correct
74 Correct 182 ms 28424 KB Output is correct
75 Correct 142 ms 15912 KB Output is correct
76 Correct 152 ms 15992 KB Output is correct
77 Correct 155 ms 16012 KB Output is correct
78 Correct 157 ms 16052 KB Output is correct
79 Correct 155 ms 15976 KB Output is correct
80 Correct 183 ms 16012 KB Output is correct
81 Correct 130 ms 16224 KB Output is correct
82 Correct 142 ms 16116 KB Output is correct
83 Correct 162 ms 20996 KB Output is correct
84 Correct 156 ms 23188 KB Output is correct
85 Correct 172 ms 22808 KB Output is correct
86 Correct 154 ms 17380 KB Output is correct
87 Correct 147 ms 16676 KB Output is correct
88 Correct 155 ms 17176 KB Output is correct
89 Correct 148 ms 17212 KB Output is correct
90 Correct 160 ms 17040 KB Output is correct
91 Correct 153 ms 17124 KB Output is correct
92 Correct 154 ms 17648 KB Output is correct
93 Correct 148 ms 19800 KB Output is correct
94 Correct 146 ms 21668 KB Output is correct
95 Correct 130 ms 20312 KB Output is correct
96 Correct 145 ms 18476 KB Output is correct
97 Correct 138 ms 16952 KB Output is correct
98 Correct 165 ms 16460 KB Output is correct
99 Correct 145 ms 16344 KB Output is correct
100 Correct 145 ms 19440 KB Output is correct
101 Correct 167 ms 17512 KB Output is correct
102 Correct 129 ms 16708 KB Output is correct
103 Correct 134 ms 16560 KB Output is correct
104 Correct 101 ms 16768 KB Output is correct
105 Correct 172 ms 25400 KB Output is correct
106 Correct 86 ms 16700 KB Output is correct
107 Correct 84 ms 16704 KB Output is correct
108 Correct 171 ms 29340 KB Output is correct
109 Correct 116 ms 16792 KB Output is correct
110 Correct 170 ms 29652 KB Output is correct
111 Correct 135 ms 15880 KB Output is correct