답안 #783569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783569 2023-07-15T04:17:40 Z horiiseun Power Plant (JOI20_power) C++17
100 / 100
120 ms 28800 KB
#include <iostream>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <random>
#include <string>
#include <bitset>
#include <cassert>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
 
#define ll long long
#define f first
#define s second
 
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
 
template<typename A> void __print(const A &x);
template<typename A, typename B> void __print(const pair<A, B> &p);
template<typename... A> void __print(const tuple<A...> &t);
template<typename T> void __print(stack<T> s);
template<typename T> void __print(queue<T> q);
template<typename T, typename... U> void __print(priority_queue<T, U...> q);
 
template<typename A> void __print(const A &x) {
    bool first = true;
    cerr << '{';
    for (const auto &i : x) {
        cerr << (first ? "" : ","), __print(i);
        first = false;
    }
    cerr << '}';
}
 
template<typename A, typename B> void __print(const pair<A, B> &p) {
    cerr << '(';
    __print(p.f);
    cerr << ',';
    __print(p.s);
    cerr << ')';
}
 
template<typename... A> void __print(const tuple<A...> &t) {
    bool first = true;
    cerr << '(';
    apply([&first] (const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
    cerr << ')';
}
 
template<typename T> void __print(stack<T> s) {
    vector<T> debugVector;
    while (!s.empty()) {
        T t = s.top();
        debugVector.push_back(t);
        s.pop();
    }
    reverse(debugVector.begin(), debugVector.end());
    __print(debugVector);
}
 
template<typename T> void __print(queue<T> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.front();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
 
template<typename T, typename... U> void __print(priority_queue<T, U...> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.top();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
 
void _print() { cerr << "]\n"; }
 
template <typename Head, typename... Tail> void _print(const Head &H, const Tail &...T) {
    __print(H);
    if (sizeof...(T)) cerr << ", ";
    _print(T...);
}
 
#ifdef DEBUG
	#define D(...) cerr << "Line: " << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
    #define D(...)
#endif

int n, dp[200005], ans;
vector<int> adj[200005];
string s;

void dfs(int curr, int par) {
    if (s[curr - 1] == '1') {
        int tmp = 0;
        for (int i : adj[curr]) {
            if (i == par) continue;
            dfs(i, curr);
            dp[curr] += dp[i];
            tmp = max(dp[i] + 1, tmp);
        }
        ans = max(ans, tmp);
        dp[curr]--;
        if (dp[curr] < 1) dp[curr] = 1;
    } else {
        for (int i : adj[curr]) {
            if (i == par) continue;
            dfs(i, curr);
            dp[curr] += dp[i];
        }
    }
    ans = max(dp[curr], ans);
}

int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 0, a, b; i < n - 1; i++) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> s;
    
    dfs(1, -1);
    
    cout << ans << "\n";
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5032 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5024 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5028 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 5024 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5032 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5024 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5028 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 5024 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5036 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5048 KB Output is correct
29 Correct 3 ms 5156 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5036 KB Output is correct
33 Correct 3 ms 5040 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5048 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5036 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5036 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 2 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5096 KB Output is correct
61 Correct 3 ms 5032 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5032 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 5024 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 4 ms 5064 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5028 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 5024 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5036 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5048 KB Output is correct
29 Correct 3 ms 5156 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5036 KB Output is correct
33 Correct 3 ms 5040 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5048 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5036 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5036 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 2 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5096 KB Output is correct
61 Correct 3 ms 5032 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 120 ms 15128 KB Output is correct
65 Correct 78 ms 15180 KB Output is correct
66 Correct 70 ms 15208 KB Output is correct
67 Correct 67 ms 15116 KB Output is correct
68 Correct 64 ms 15184 KB Output is correct
69 Correct 81 ms 15088 KB Output is correct
70 Correct 86 ms 15120 KB Output is correct
71 Correct 82 ms 15208 KB Output is correct
72 Correct 88 ms 15208 KB Output is correct
73 Correct 102 ms 27720 KB Output is correct
74 Correct 103 ms 27752 KB Output is correct
75 Correct 98 ms 15012 KB Output is correct
76 Correct 106 ms 15064 KB Output is correct
77 Correct 85 ms 14980 KB Output is correct
78 Correct 62 ms 14988 KB Output is correct
79 Correct 69 ms 15080 KB Output is correct
80 Correct 84 ms 14976 KB Output is correct
81 Correct 84 ms 15532 KB Output is correct
82 Correct 88 ms 15332 KB Output is correct
83 Correct 79 ms 20212 KB Output is correct
84 Correct 106 ms 22340 KB Output is correct
85 Correct 77 ms 22100 KB Output is correct
86 Correct 82 ms 16528 KB Output is correct
87 Correct 87 ms 15956 KB Output is correct
88 Correct 88 ms 16336 KB Output is correct
89 Correct 93 ms 16404 KB Output is correct
90 Correct 78 ms 16192 KB Output is correct
91 Correct 77 ms 16404 KB Output is correct
92 Correct 70 ms 16672 KB Output is correct
93 Correct 66 ms 19024 KB Output is correct
94 Correct 76 ms 20880 KB Output is correct
95 Correct 64 ms 19532 KB Output is correct
96 Correct 71 ms 17728 KB Output is correct
97 Correct 81 ms 16180 KB Output is correct
98 Correct 76 ms 15720 KB Output is correct
99 Correct 83 ms 15496 KB Output is correct
100 Correct 92 ms 18708 KB Output is correct
101 Correct 84 ms 16616 KB Output is correct
102 Correct 70 ms 15884 KB Output is correct
103 Correct 100 ms 15752 KB Output is correct
104 Correct 51 ms 15228 KB Output is correct
105 Correct 102 ms 24628 KB Output is correct
106 Correct 52 ms 15880 KB Output is correct
107 Correct 46 ms 15916 KB Output is correct
108 Correct 86 ms 28500 KB Output is correct
109 Correct 63 ms 15224 KB Output is correct
110 Correct 103 ms 28800 KB Output is correct
111 Correct 63 ms 15060 KB Output is correct