답안 #434927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434927 2021-06-22T10:44:12 Z xuliu Power Plant (JOI20_power) C++14
47 / 100
1500 ms 15420 KB
#include <bits/stdc++.h>
using namespace std;

// Power - subtask 2

#define ll long long
#define ull unsigned LL
#define ld long double
#define debug if(0)
#define fastio ios_base::sync_with_stdio(0); cin.tie()

const int N = 2e5 + 4;
string s;
vector<int> V[N], dp(N, 0);
bool vis[N];

void clear(int n) {
	for(int i=1; i<=n; i++) {
		dp[i] = 0;
		vis[i] = 0;
	}
}

void dfs(int v, int root) {
	vis[v] = 1;
	dp[v] = s[v-1] - '0';
	int rb = 0, rc = 0;
	for(int i=0; i<(int) V[v].size(); i++) {
		int u = V[v][i];
		if(!vis[u]) {
			dfs(u, root);
			rb += dp[u];
			rc = max(rc, dp[u]);
		}
	}
	if(v == root)
		dp[v] = rc + 1;
	else {
		rb -= s[v-1] - '0';
		dp[v] = max(dp[v], rb);
	}
	debug cerr<<"dp["<<v<<"] = "<<dp[v]<<"\n";
}

int main() {
	fastio;
	int n;
	cin>>n;
	for(int i=0; i<(n-1); i++) {
		int a, b;
		cin>>a>>b;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	cin>>s;
	int ans = 0;
	for(int i=1; i<=n; i++) {
		if(s[i-1] == '1') {
			clear(n);
			dfs(i, i);
			ans = max(ans, dp[i]);
		}
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 5 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 5 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 5 ms 5708 KB Output is correct
7 Correct 5 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 5 ms 5708 KB Output is correct
10 Correct 5 ms 5708 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 5 ms 5708 KB Output is correct
13 Correct 5 ms 5708 KB Output is correct
14 Correct 6 ms 5708 KB Output is correct
15 Correct 5 ms 5808 KB Output is correct
16 Correct 5 ms 5708 KB Output is correct
17 Correct 5 ms 5708 KB Output is correct
18 Correct 5 ms 5708 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 5 ms 5708 KB Output is correct
21 Correct 4 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 5 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 5 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 5 ms 5708 KB Output is correct
7 Correct 5 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 5 ms 5708 KB Output is correct
10 Correct 5 ms 5708 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 5 ms 5708 KB Output is correct
13 Correct 5 ms 5708 KB Output is correct
14 Correct 6 ms 5708 KB Output is correct
15 Correct 5 ms 5808 KB Output is correct
16 Correct 5 ms 5708 KB Output is correct
17 Correct 5 ms 5708 KB Output is correct
18 Correct 5 ms 5708 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 5 ms 5708 KB Output is correct
21 Correct 4 ms 5708 KB Output is correct
22 Correct 113 ms 5836 KB Output is correct
23 Correct 124 ms 5836 KB Output is correct
24 Correct 87 ms 5836 KB Output is correct
25 Correct 71 ms 5836 KB Output is correct
26 Correct 31 ms 5820 KB Output is correct
27 Correct 15 ms 5824 KB Output is correct
28 Correct 6 ms 5836 KB Output is correct
29 Correct 142 ms 5952 KB Output is correct
30 Correct 70 ms 5964 KB Output is correct
31 Correct 104 ms 5836 KB Output is correct
32 Correct 54 ms 5804 KB Output is correct
33 Correct 99 ms 5836 KB Output is correct
34 Correct 55 ms 5828 KB Output is correct
35 Correct 30 ms 5844 KB Output is correct
36 Correct 15 ms 5836 KB Output is correct
37 Correct 96 ms 5836 KB Output is correct
38 Correct 57 ms 5772 KB Output is correct
39 Correct 121 ms 5952 KB Output is correct
40 Correct 62 ms 5964 KB Output is correct
41 Correct 34 ms 5964 KB Output is correct
42 Correct 60 ms 5836 KB Output is correct
43 Correct 16 ms 5836 KB Output is correct
44 Correct 112 ms 5836 KB Output is correct
45 Correct 76 ms 5836 KB Output is correct
46 Correct 52 ms 5836 KB Output is correct
47 Correct 37 ms 5824 KB Output is correct
48 Correct 96 ms 5964 KB Output is correct
49 Correct 108 ms 5964 KB Output is correct
50 Correct 99 ms 5812 KB Output is correct
51 Correct 99 ms 5836 KB Output is correct
52 Correct 102 ms 5824 KB Output is correct
53 Correct 78 ms 5964 KB Output is correct
54 Correct 97 ms 5836 KB Output is correct
55 Correct 99 ms 5860 KB Output is correct
56 Correct 7 ms 5904 KB Output is correct
57 Correct 7 ms 6028 KB Output is correct
58 Correct 70 ms 5872 KB Output is correct
59 Correct 72 ms 5836 KB Output is correct
60 Correct 6 ms 5964 KB Output is correct
61 Correct 5 ms 5836 KB Output is correct
62 Correct 7 ms 5964 KB Output is correct
63 Correct 98 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 5 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 5 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 5 ms 5708 KB Output is correct
7 Correct 5 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 5 ms 5708 KB Output is correct
10 Correct 5 ms 5708 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 5 ms 5708 KB Output is correct
13 Correct 5 ms 5708 KB Output is correct
14 Correct 6 ms 5708 KB Output is correct
15 Correct 5 ms 5808 KB Output is correct
16 Correct 5 ms 5708 KB Output is correct
17 Correct 5 ms 5708 KB Output is correct
18 Correct 5 ms 5708 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 5 ms 5708 KB Output is correct
21 Correct 4 ms 5708 KB Output is correct
22 Correct 113 ms 5836 KB Output is correct
23 Correct 124 ms 5836 KB Output is correct
24 Correct 87 ms 5836 KB Output is correct
25 Correct 71 ms 5836 KB Output is correct
26 Correct 31 ms 5820 KB Output is correct
27 Correct 15 ms 5824 KB Output is correct
28 Correct 6 ms 5836 KB Output is correct
29 Correct 142 ms 5952 KB Output is correct
30 Correct 70 ms 5964 KB Output is correct
31 Correct 104 ms 5836 KB Output is correct
32 Correct 54 ms 5804 KB Output is correct
33 Correct 99 ms 5836 KB Output is correct
34 Correct 55 ms 5828 KB Output is correct
35 Correct 30 ms 5844 KB Output is correct
36 Correct 15 ms 5836 KB Output is correct
37 Correct 96 ms 5836 KB Output is correct
38 Correct 57 ms 5772 KB Output is correct
39 Correct 121 ms 5952 KB Output is correct
40 Correct 62 ms 5964 KB Output is correct
41 Correct 34 ms 5964 KB Output is correct
42 Correct 60 ms 5836 KB Output is correct
43 Correct 16 ms 5836 KB Output is correct
44 Correct 112 ms 5836 KB Output is correct
45 Correct 76 ms 5836 KB Output is correct
46 Correct 52 ms 5836 KB Output is correct
47 Correct 37 ms 5824 KB Output is correct
48 Correct 96 ms 5964 KB Output is correct
49 Correct 108 ms 5964 KB Output is correct
50 Correct 99 ms 5812 KB Output is correct
51 Correct 99 ms 5836 KB Output is correct
52 Correct 102 ms 5824 KB Output is correct
53 Correct 78 ms 5964 KB Output is correct
54 Correct 97 ms 5836 KB Output is correct
55 Correct 99 ms 5860 KB Output is correct
56 Correct 7 ms 5904 KB Output is correct
57 Correct 7 ms 6028 KB Output is correct
58 Correct 70 ms 5872 KB Output is correct
59 Correct 72 ms 5836 KB Output is correct
60 Correct 6 ms 5964 KB Output is correct
61 Correct 5 ms 5836 KB Output is correct
62 Correct 7 ms 5964 KB Output is correct
63 Correct 98 ms 5836 KB Output is correct
64 Execution timed out 1582 ms 15420 KB Time limit exceeded
65 Halted 0 ms 0 KB -