답안 #849771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849771 2023-09-15T10:23:25 Z Abito Power Plant (JOI20_power) C++14
47 / 100
50 ms 752 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){
    //int s=bool(p);
    dp[node]=0;
    for (auto u:adj[node]) if (u!=p) dp[node]+=rec(u,node);
    if (adj[node].size()<=1) dp[node]+=a[node];
    else dp[node]-=a[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<<endl;
    //for (int i=1;i<=n;i++) cout<<dp[i]<<' ';
    //cout<<endl;
    return 0;
}

Compilation message

power.cpp: In function 'int32_t main()':
power.cpp:34:15: warning: variable 'ansi' set but not used [-Wunused-but-set-variable]
   34 |     int ans=0,ansi=0;
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 35 ms 344 KB Output is correct
23 Correct 36 ms 344 KB Output is correct
24 Correct 38 ms 344 KB Output is correct
25 Correct 35 ms 344 KB Output is correct
26 Correct 44 ms 596 KB Output is correct
27 Correct 40 ms 564 KB Output is correct
28 Correct 35 ms 344 KB Output is correct
29 Correct 48 ms 600 KB Output is correct
30 Correct 49 ms 600 KB Output is correct
31 Correct 32 ms 600 KB Output is correct
32 Correct 32 ms 344 KB Output is correct
33 Correct 36 ms 344 KB Output is correct
34 Correct 36 ms 344 KB Output is correct
35 Correct 37 ms 344 KB Output is correct
36 Correct 37 ms 344 KB Output is correct
37 Correct 28 ms 344 KB Output is correct
38 Correct 31 ms 344 KB Output is correct
39 Correct 44 ms 752 KB Output is correct
40 Correct 43 ms 600 KB Output is correct
41 Correct 43 ms 600 KB Output is correct
42 Correct 40 ms 600 KB Output is correct
43 Correct 50 ms 600 KB Output is correct
44 Correct 35 ms 600 KB Output is correct
45 Correct 42 ms 600 KB Output is correct
46 Correct 35 ms 600 KB Output is correct
47 Correct 34 ms 600 KB Output is correct
48 Correct 36 ms 624 KB Output is correct
49 Correct 35 ms 600 KB Output is correct
50 Correct 35 ms 612 KB Output is correct
51 Correct 35 ms 600 KB Output is correct
52 Correct 34 ms 344 KB Output is correct
53 Correct 32 ms 600 KB Output is correct
54 Correct 35 ms 604 KB Output is correct
55 Correct 34 ms 600 KB Output is correct
56 Correct 21 ms 600 KB Output is correct
57 Correct 49 ms 680 KB Output is correct
58 Correct 21 ms 344 KB Output is correct
59 Correct 21 ms 344 KB Output is correct
60 Correct 49 ms 600 KB Output is correct
61 Correct 21 ms 348 KB Output is correct
62 Correct 47 ms 600 KB Output is correct
63 Correct 31 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 35 ms 344 KB Output is correct
23 Correct 36 ms 344 KB Output is correct
24 Correct 38 ms 344 KB Output is correct
25 Correct 35 ms 344 KB Output is correct
26 Correct 44 ms 596 KB Output is correct
27 Correct 40 ms 564 KB Output is correct
28 Correct 35 ms 344 KB Output is correct
29 Correct 48 ms 600 KB Output is correct
30 Correct 49 ms 600 KB Output is correct
31 Correct 32 ms 600 KB Output is correct
32 Correct 32 ms 344 KB Output is correct
33 Correct 36 ms 344 KB Output is correct
34 Correct 36 ms 344 KB Output is correct
35 Correct 37 ms 344 KB Output is correct
36 Correct 37 ms 344 KB Output is correct
37 Correct 28 ms 344 KB Output is correct
38 Correct 31 ms 344 KB Output is correct
39 Correct 44 ms 752 KB Output is correct
40 Correct 43 ms 600 KB Output is correct
41 Correct 43 ms 600 KB Output is correct
42 Correct 40 ms 600 KB Output is correct
43 Correct 50 ms 600 KB Output is correct
44 Correct 35 ms 600 KB Output is correct
45 Correct 42 ms 600 KB Output is correct
46 Correct 35 ms 600 KB Output is correct
47 Correct 34 ms 600 KB Output is correct
48 Correct 36 ms 624 KB Output is correct
49 Correct 35 ms 600 KB Output is correct
50 Correct 35 ms 612 KB Output is correct
51 Correct 35 ms 600 KB Output is correct
52 Correct 34 ms 344 KB Output is correct
53 Correct 32 ms 600 KB Output is correct
54 Correct 35 ms 604 KB Output is correct
55 Correct 34 ms 600 KB Output is correct
56 Correct 21 ms 600 KB Output is correct
57 Correct 49 ms 680 KB Output is correct
58 Correct 21 ms 344 KB Output is correct
59 Correct 21 ms 344 KB Output is correct
60 Correct 49 ms 600 KB Output is correct
61 Correct 21 ms 348 KB Output is correct
62 Correct 47 ms 600 KB Output is correct
63 Correct 31 ms 344 KB Output is correct
64 Runtime error 1 ms 600 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -