제출 #1037883

#제출 시각아이디문제언어결과실행 시간메모리
1037883phongPower Plant (JOI20_power)C++17
100 / 100
68 ms30800 KiB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
#define int long long
const int nmax = 2e5 + 5, N = 1e5;
const ll oo = 1e18;
const int lg = 19, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;

int n;
vector<int> adj[nmax];
int a[nmax], dp[nmax], ans = 0;

void dfs(int u, int p){
    bool ok = 0, ok2 = 0;
    for(auto v : adj[u]){
        if(v == p) continue;
        dfs(v, u);
        dp[u] += dp[v];
        ans = max(ans, dp[v] + a[u]);
    }
    dp[u] -= a[u];
    dp[u] = max(dp[u], a[u]);
    ans = max(ans, dp[u]);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
////    freopen(task".inp", "r", stdin);
//    freopen(task".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; ++i){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 1; i <= n; ++i){
        char x;
        cin >> x;
        a[i] = (x == '1');
    }
    dfs(1, -1);
//    debug(a, n);
    cout << ans;
}
/*
4 3
0 1 1
1 1 0
0 0 0
0 0 0
5
2 2
1 3
3 2
4 3
1 3


*/

컴파일 시 표준 에러 (stderr) 메시지

power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:24:10: warning: unused variable 'ok' [-Wunused-variable]
   24 |     bool ok = 0, ok2 = 0;
      |          ^~
power.cpp:24:18: warning: unused variable 'ok2' [-Wunused-variable]
   24 |     bool ok = 0, ok2 = 0;
      |                  ^~~
power.cpp: At global scope:
power.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...