답안 #763100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763100 2023-06-22T03:32:33 Z vjudge1 Power Plant (JOI20_power) C++14
0 / 100
3 ms 4948 KB
#include <bits/stdc++.h>
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define int long long
#define endl '\n'
using namespace std;
const int MAXN = 1e18;
int mod = 1e9 + 7;
int a[200005];
int dp[200005];
bool state[200005];
vector<int> w[200005];
int ans = 0;
void DFS(int u,int par)
{
	int cnt = 0;
	for(int v:w[u])
	{
		if(v == par)
		{
			continue;
		}
		DFS(v,u);
		dp[u] += dp[v];
		cnt = max(cnt,dp[v]);
	}
	if(state[u] = 1)
	{
		ans = max(ans,cnt + 1);
		dp[u] = max(1ll,dp[u] - 1);
	}
	ans = max(ans,dp[u]);
}
void AcSolution()
{
	int n;
	cin >> n;
	for(int i = 1;i < n;i++)
	{
		int u,v;
		cin >> u >> v;
		w[u].push_back(v);
		w[v].push_back(u);
	}
	for(int i = 1;i <= n;i++)
	{
		char x;
		cin >> x;
		if(x == '1')
		{
			state[i] = 1;
		}
		else
		{
			state[i] = 0;
		}
	}
	DFS(1,0);
	cout << ans << endl;
}
signed main()
{
//	freopen("BDIGIT.inp", "r",stdin);
//    freopen("BDIGIT.out", "w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
	 	AcSolution();
	}
}

Compilation message

power.cpp: In function 'void DFS(long long int, long long int)':
power.cpp:29:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   29 |  if(state[u] = 1)
      |     ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 2 ms 4904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 2 ms 4904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 2 ms 4904 KB Output isn't correct
3 Halted 0 ms 0 KB -