답안 #849769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849769 2023-09-15T10:05:05 Z Abito Power Plant (JOI20_power) C++14
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2005;
int n,dp[N];
vector<int> adj[N];
bool a[N];
int rec(int node,int p){
    if (adj[node].size()>1) dp[node]=-a[node];
    else dp[node]=a[node];
    for (auto u:adj[node]) if (u!=p) dp[node]+=rec(u,node);
    return dp[node]=max(dp[node],(int)a[node]);
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        adj[x].pb(y);adj[y].pb(x);
    }for (int i=1;i<=n;i++){char c;cin>>c;a[i]=c-'0';}
    int ans=0,ansi=0;
    for (int i=1;i<=n;i++){
        int x=rec(i,0);
        if (x>ans){
            ans=x;
            ansi=i;
        }
    }cout<<ans<<' '<<ansi<<endl;
    //for (int i=1;i<=n;i++) cout<<dp[i]<<' ';
    //cout<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -