답안 #1120084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1120084 2024-11-28T00:51:23 Z irmuun Power Plant (JOI20_power) C++17
47 / 100
1500 ms 80196 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int N=2e5+5;

int n,ans=0;
vector<int>g[N];
string s;
int e[N];
map<pair<int,int>,bool>run;
map<pair<int,int>,int>val;

int dfs(int x,int p){
    if(run[{x,p}]) return val[{x,p}];
    run[{x,p}]=true;
    int cur=0;
    for(int y:g[x]){
        if(y!=p){
            cur+=dfs(y,x);
        }
    }
    cur=max(cur-e[x],e[x]);
    return val[{x,p}]=cur;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            e[i]=1;
        }
        else{
            e[i]=0;
        }
    }
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            dfs(i,i);
            for(int j:g[i]){
                ans=max(ans,val[{j,i}]+1);
            }
            ans=max(ans,val[{i,i}]);
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5712 KB Output is correct
4 Correct 2 ms 5712 KB Output is correct
5 Correct 2 ms 5712 KB Output is correct
6 Correct 3 ms 5712 KB Output is correct
7 Correct 2 ms 5712 KB Output is correct
8 Correct 2 ms 5712 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 2 ms 5880 KB Output is correct
11 Correct 2 ms 5712 KB Output is correct
12 Correct 2 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 2 ms 5712 KB Output is correct
15 Correct 2 ms 5712 KB Output is correct
16 Correct 2 ms 5772 KB Output is correct
17 Correct 2 ms 5712 KB Output is correct
18 Correct 2 ms 5712 KB Output is correct
19 Correct 3 ms 5712 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5712 KB Output is correct
4 Correct 2 ms 5712 KB Output is correct
5 Correct 2 ms 5712 KB Output is correct
6 Correct 3 ms 5712 KB Output is correct
7 Correct 2 ms 5712 KB Output is correct
8 Correct 2 ms 5712 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 2 ms 5880 KB Output is correct
11 Correct 2 ms 5712 KB Output is correct
12 Correct 2 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 2 ms 5712 KB Output is correct
15 Correct 2 ms 5712 KB Output is correct
16 Correct 2 ms 5772 KB Output is correct
17 Correct 2 ms 5712 KB Output is correct
18 Correct 2 ms 5712 KB Output is correct
19 Correct 3 ms 5712 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5712 KB Output is correct
22 Correct 7 ms 6480 KB Output is correct
23 Correct 7 ms 6380 KB Output is correct
24 Correct 6 ms 6480 KB Output is correct
25 Correct 5 ms 6240 KB Output is correct
26 Correct 5 ms 6236 KB Output is correct
27 Correct 4 ms 6080 KB Output is correct
28 Correct 3 ms 5976 KB Output is correct
29 Correct 6 ms 6748 KB Output is correct
30 Correct 5 ms 6472 KB Output is correct
31 Correct 9 ms 6488 KB Output is correct
32 Correct 8 ms 6232 KB Output is correct
33 Correct 6 ms 6540 KB Output is correct
34 Correct 6 ms 6224 KB Output is correct
35 Correct 5 ms 6224 KB Output is correct
36 Correct 4 ms 6224 KB Output is correct
37 Correct 95 ms 6484 KB Output is correct
38 Correct 15 ms 6240 KB Output is correct
39 Correct 7 ms 6480 KB Output is correct
40 Correct 7 ms 6412 KB Output is correct
41 Correct 5 ms 6224 KB Output is correct
42 Correct 8 ms 6224 KB Output is correct
43 Correct 4 ms 6224 KB Output is correct
44 Correct 11 ms 6480 KB Output is correct
45 Correct 10 ms 6480 KB Output is correct
46 Correct 8 ms 6224 KB Output is correct
47 Correct 6 ms 6224 KB Output is correct
48 Correct 135 ms 6544 KB Output is correct
49 Correct 53 ms 6492 KB Output is correct
50 Correct 33 ms 6640 KB Output is correct
51 Correct 20 ms 6636 KB Output is correct
52 Correct 8 ms 6604 KB Output is correct
53 Correct 28 ms 6364 KB Output is correct
54 Correct 14 ms 6460 KB Output is correct
55 Correct 9 ms 6548 KB Output is correct
56 Correct 5 ms 5968 KB Output is correct
57 Correct 3 ms 6224 KB Output is correct
58 Correct 582 ms 6360 KB Output is correct
59 Correct 631 ms 6556 KB Output is correct
60 Correct 5 ms 6480 KB Output is correct
61 Correct 3 ms 5968 KB Output is correct
62 Correct 4 ms 6480 KB Output is correct
63 Correct 9 ms 6472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5712 KB Output is correct
4 Correct 2 ms 5712 KB Output is correct
5 Correct 2 ms 5712 KB Output is correct
6 Correct 3 ms 5712 KB Output is correct
7 Correct 2 ms 5712 KB Output is correct
8 Correct 2 ms 5712 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 2 ms 5880 KB Output is correct
11 Correct 2 ms 5712 KB Output is correct
12 Correct 2 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 2 ms 5712 KB Output is correct
15 Correct 2 ms 5712 KB Output is correct
16 Correct 2 ms 5772 KB Output is correct
17 Correct 2 ms 5712 KB Output is correct
18 Correct 2 ms 5712 KB Output is correct
19 Correct 3 ms 5712 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5712 KB Output is correct
22 Correct 7 ms 6480 KB Output is correct
23 Correct 7 ms 6380 KB Output is correct
24 Correct 6 ms 6480 KB Output is correct
25 Correct 5 ms 6240 KB Output is correct
26 Correct 5 ms 6236 KB Output is correct
27 Correct 4 ms 6080 KB Output is correct
28 Correct 3 ms 5976 KB Output is correct
29 Correct 6 ms 6748 KB Output is correct
30 Correct 5 ms 6472 KB Output is correct
31 Correct 9 ms 6488 KB Output is correct
32 Correct 8 ms 6232 KB Output is correct
33 Correct 6 ms 6540 KB Output is correct
34 Correct 6 ms 6224 KB Output is correct
35 Correct 5 ms 6224 KB Output is correct
36 Correct 4 ms 6224 KB Output is correct
37 Correct 95 ms 6484 KB Output is correct
38 Correct 15 ms 6240 KB Output is correct
39 Correct 7 ms 6480 KB Output is correct
40 Correct 7 ms 6412 KB Output is correct
41 Correct 5 ms 6224 KB Output is correct
42 Correct 8 ms 6224 KB Output is correct
43 Correct 4 ms 6224 KB Output is correct
44 Correct 11 ms 6480 KB Output is correct
45 Correct 10 ms 6480 KB Output is correct
46 Correct 8 ms 6224 KB Output is correct
47 Correct 6 ms 6224 KB Output is correct
48 Correct 135 ms 6544 KB Output is correct
49 Correct 53 ms 6492 KB Output is correct
50 Correct 33 ms 6640 KB Output is correct
51 Correct 20 ms 6636 KB Output is correct
52 Correct 8 ms 6604 KB Output is correct
53 Correct 28 ms 6364 KB Output is correct
54 Correct 14 ms 6460 KB Output is correct
55 Correct 9 ms 6548 KB Output is correct
56 Correct 5 ms 5968 KB Output is correct
57 Correct 3 ms 6224 KB Output is correct
58 Correct 582 ms 6360 KB Output is correct
59 Correct 631 ms 6556 KB Output is correct
60 Correct 5 ms 6480 KB Output is correct
61 Correct 3 ms 5968 KB Output is correct
62 Correct 4 ms 6480 KB Output is correct
63 Correct 9 ms 6472 KB Output is correct
64 Execution timed out 1558 ms 80196 KB Time limit exceeded
65 Halted 0 ms 0 KB -