답안 #765987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765987 2023-06-25T08:28:18 Z yusuf12360 Power Plant (JOI20_power) C++14
0 / 100
1 ms 316 KB
#include<bits/stdc++.h>
using namespace std;
int ans=0;
vector<int> res;
vector<vector<int>> adj;
string s;
void dfs1(int u=0, int p=-1) {
	res[u]=s[u]-'0';
	for(int pp : adj[u]) {
		if(pp==p) continue;
		dfs1(pp, u);
		if(s[pp]=='1') res[u]++;
		else res[u]+=res[pp];
	}
}
void dfs2(int u=0, int p=-1, int to_p=0) {
	ans=max(ans, res[u]+to_p-2*(s[u]=='1'));
	for(int pp : adj[u]) {
		if(pp==p) continue;
		if(s[u]=='1') dfs2(pp, u, 1);
		else dfs2(pp, u, to_p+res[u]-res[pp]);
	}
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	res.resize(n); adj.resize(n);
	while(--n) {
		int u, v; cin >> u >> v; --u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);}
	cin >> s;
	dfs1();
	for(int p : res) cout << p << ' '; cout << endl;
	dfs2();
	cout << ans << '\n';
	return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:34:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   34 |  for(int p : res) cout << p << ' '; cout << endl;
      |  ^~~
power.cpp:34:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   34 |  for(int p : res) cout << p << ' '; cout << endl;
      |                                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -