답안 #313082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313082 2020-10-15T07:35:10 Z Jarif_Rahman Power Plant (JOI20_power) C++17
6 / 100
2 ms 512 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n; str s;
vector <vector<int>> v;
ll ans =  0;
ll dfs(int nd, int ss){
    ll r = '0'-s[nd];
    bool bl = (r==-1);
    ll mx = 0;
    if(ss == -1 && s[nd] == '1' && v[nd].size() == 1) r = 1;
    else if(v[nd].size() <= 2 && s[nd] == '1' && ss != -1) r = 1;
    for(int x: v[nd]) if(x != ss){
        ll y =dfs(x, nd);
        mx = max(mx, y);
        r+=y;
    }
    if(bl && nd == 1) r = max(r, mx+1);
    ans = max(ans, max(r, (ll)s[nd] - '0'));
    if(v[nd].size() <= 2 && s[nd] == '1' && ss != -1)r-=2;
    return max(r, (ll)s[nd] - '0');
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    v = vector<vector<int>> (n+1);
    for(int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin >> s;
    s = "x"+s;
    ans = max(ans, dfs(1, -1));
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Output isn't correct
33 Halted 0 ms 0 KB -