답안 #391355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391355 2021-04-18T15:55:14 Z lukameladze Power Plant (JOI20_power) C++14
0 / 100
6 ms 7372 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+5;
long long par[N],dp[N],dp1[N],n,a,b,bb,ans;
vector <long long> v[N];
string s;
void dfs (int a, int p) {
     int ff=0;
     for (int i=0; i<v[a].size(); i++) {
          if (v[a][i]!=p) {
               dfs(v[a][i],a);
               dp[a]+=dp[v[a][i]];
               if (s[a]=='1' && !ff) dp[a]--, ff=1;
               dp1[a]+=dp1[v[a][i]];
          }
     }
     dp1[a]++;
    if (s[a]=='1') dp[a]=max(1LL, dp[a]);
    if (s[a]=='0') dp[a]=max(0LL,dp[a]);
}
int main() {
     cin>>n;
     for (int i=1; i<=n-1; i++) {
          cin>>a>>b;
          v[a].pb(b);
          v[b].pb(a);
     }
     cin>>s;
     s="@"+s;
     dfs(1,0);
     for (int i=1; i<=n; i++) {
          if (dp1[1]-dp1[i]>0) bb=1; else bb=0;
          ans=max(ans,dp[i]+bb);
     }
     cout<<ans<<endl;
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |      for (int i=0; i<v[a].size(); i++) {
      |                    ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 6 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7348 KB Output is correct
12 Correct 5 ms 7352 KB Output is correct
13 Correct 5 ms 7244 KB Output is correct
14 Correct 5 ms 7352 KB Output is correct
15 Incorrect 5 ms 7244 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 6 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7348 KB Output is correct
12 Correct 5 ms 7352 KB Output is correct
13 Correct 5 ms 7244 KB Output is correct
14 Correct 5 ms 7352 KB Output is correct
15 Incorrect 5 ms 7244 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 6 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7348 KB Output is correct
12 Correct 5 ms 7352 KB Output is correct
13 Correct 5 ms 7244 KB Output is correct
14 Correct 5 ms 7352 KB Output is correct
15 Incorrect 5 ms 7244 KB Output isn't correct
16 Halted 0 ms 0 KB -