# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
294089 | 2020-09-08T15:14:19 Z | BThero | Power Plant (JOI20_power) | C++17 | 1 ms | 384 KB |
// chrono::system_clock::now().time_since_epoch().count() #include<bits/stdc++.h> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << " = " << x << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = (int)2e3 + 5; vector<int> adj[MAXN]; char can[MAXN]; int dp[MAXN]; int n; void dfs(int v, int pr = -1) { vector<int> sons; for (int to : adj[v]) { if (to != pr) { dfs(to, v); sons.pb(to); } } if (can[v] == '1') { dp[v] = 1; int S = -1; for (int to : sons) { S += dp[to]; } dp[v] = max(dp[v], S); } else { dp[v] = 0; for (int to : sons) { dp[v] += dp[to]; } } } void solve() { scanf("%d", &n); for (int i = 1; i < n; ++i) { int u, v; scanf("%d %d", &u, &v); adj[u].pb(v); adj[v].pb(u); } scanf("%s", can + 1); int ans = 0; for (int root = 1; root <= n; ++root) { dfs(root); ans = max(ans, dp[root]); } printf("%d\n", ans); } int main() { int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Incorrect | 0 ms | 384 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Incorrect | 0 ms | 384 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Incorrect | 0 ms | 384 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |