답안 #924963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924963 2024-02-10T07:22:44 Z pan Power Plant (JOI20_power) C++17
100 / 100
119 ms 32852 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, x, y, answer = 0;
string power;
vector<ll> adj[200005];
ll dp[200005], ans[200005];
// dp -> if 0, 1 can be chosen freely under this subtree
vector<ll> visited;
 
void dfs(ll from)
{
	visited[from] = true;
	ll summ = 0, maxx = 0;
	for (ll u: adj[from])
	{
		if (visited[u]) continue;
		dfs(u);
		summ+=dp[u];
		maxx = max(maxx, dp[u]);
	}
	if (power[from-1]=='1') {ans[from] = max(summ-1, maxx + 1); dp[from] = max(1LL, summ-1);}
	// to make below "activated valid, current from must be broken -> summ-1
	// else all must be disabled, with only current from left activated
	else {ans[from] = dp[from] = summ;}
    answer = max(answer, ans[from]);
 
}
int main()
{
	input(n);
	for (ll i=0; i<n-1; ++i)
	{
		input(x); input(y);
		adj[x].pb(y);
		adj[y].pb(x);
	}
	cin >> power;
	visited.assign(n+1, false);
	dfs(1);
	print(answer, '\n');
	return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
power.cpp:57:2: note: in expansion of macro 'input'
   57 |  input(n);
      |  ^~~~~
power.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
power.cpp:60:3: note: in expansion of macro 'input'
   60 |   input(x); input(y);
      |   ^~~~~
power.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
power.cpp:60:13: note: in expansion of macro 'input'
   60 |   input(x); input(y);
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Correct 2 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8084 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8084 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8028 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Correct 2 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8084 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8084 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8028 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 2 ms 8028 KB Output is correct
22 Correct 3 ms 8028 KB Output is correct
23 Correct 2 ms 8220 KB Output is correct
24 Correct 3 ms 8028 KB Output is correct
25 Correct 2 ms 8280 KB Output is correct
26 Correct 3 ms 8028 KB Output is correct
27 Correct 3 ms 8096 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8284 KB Output is correct
30 Correct 3 ms 8284 KB Output is correct
31 Correct 2 ms 8024 KB Output is correct
32 Correct 2 ms 8028 KB Output is correct
33 Correct 3 ms 8024 KB Output is correct
34 Correct 3 ms 8028 KB Output is correct
35 Correct 2 ms 8100 KB Output is correct
36 Correct 2 ms 8028 KB Output is correct
37 Correct 2 ms 8024 KB Output is correct
38 Correct 2 ms 8024 KB Output is correct
39 Correct 3 ms 8024 KB Output is correct
40 Correct 3 ms 8024 KB Output is correct
41 Correct 2 ms 8284 KB Output is correct
42 Correct 2 ms 8028 KB Output is correct
43 Correct 3 ms 8112 KB Output is correct
44 Correct 3 ms 8028 KB Output is correct
45 Correct 3 ms 8028 KB Output is correct
46 Correct 2 ms 8028 KB Output is correct
47 Correct 2 ms 8028 KB Output is correct
48 Correct 2 ms 8284 KB Output is correct
49 Correct 2 ms 8284 KB Output is correct
50 Correct 4 ms 8100 KB Output is correct
51 Correct 3 ms 8028 KB Output is correct
52 Correct 2 ms 8028 KB Output is correct
53 Correct 3 ms 8028 KB Output is correct
54 Correct 3 ms 8028 KB Output is correct
55 Correct 3 ms 8104 KB Output is correct
56 Correct 2 ms 8028 KB Output is correct
57 Correct 3 ms 8284 KB Output is correct
58 Correct 3 ms 8100 KB Output is correct
59 Correct 2 ms 8028 KB Output is correct
60 Correct 3 ms 8284 KB Output is correct
61 Correct 2 ms 8024 KB Output is correct
62 Correct 3 ms 8544 KB Output is correct
63 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Correct 2 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8084 KB Output is correct
10 Correct 2 ms 8280 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8084 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8028 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 2 ms 8028 KB Output is correct
22 Correct 3 ms 8028 KB Output is correct
23 Correct 2 ms 8220 KB Output is correct
24 Correct 3 ms 8028 KB Output is correct
25 Correct 2 ms 8280 KB Output is correct
26 Correct 3 ms 8028 KB Output is correct
27 Correct 3 ms 8096 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8284 KB Output is correct
30 Correct 3 ms 8284 KB Output is correct
31 Correct 2 ms 8024 KB Output is correct
32 Correct 2 ms 8028 KB Output is correct
33 Correct 3 ms 8024 KB Output is correct
34 Correct 3 ms 8028 KB Output is correct
35 Correct 2 ms 8100 KB Output is correct
36 Correct 2 ms 8028 KB Output is correct
37 Correct 2 ms 8024 KB Output is correct
38 Correct 2 ms 8024 KB Output is correct
39 Correct 3 ms 8024 KB Output is correct
40 Correct 3 ms 8024 KB Output is correct
41 Correct 2 ms 8284 KB Output is correct
42 Correct 2 ms 8028 KB Output is correct
43 Correct 3 ms 8112 KB Output is correct
44 Correct 3 ms 8028 KB Output is correct
45 Correct 3 ms 8028 KB Output is correct
46 Correct 2 ms 8028 KB Output is correct
47 Correct 2 ms 8028 KB Output is correct
48 Correct 2 ms 8284 KB Output is correct
49 Correct 2 ms 8284 KB Output is correct
50 Correct 4 ms 8100 KB Output is correct
51 Correct 3 ms 8028 KB Output is correct
52 Correct 2 ms 8028 KB Output is correct
53 Correct 3 ms 8028 KB Output is correct
54 Correct 3 ms 8028 KB Output is correct
55 Correct 3 ms 8104 KB Output is correct
56 Correct 2 ms 8028 KB Output is correct
57 Correct 3 ms 8284 KB Output is correct
58 Correct 3 ms 8100 KB Output is correct
59 Correct 2 ms 8028 KB Output is correct
60 Correct 3 ms 8284 KB Output is correct
61 Correct 2 ms 8024 KB Output is correct
62 Correct 3 ms 8544 KB Output is correct
63 Correct 2 ms 8028 KB Output is correct
64 Correct 86 ms 20200 KB Output is correct
65 Correct 82 ms 20196 KB Output is correct
66 Correct 98 ms 20016 KB Output is correct
67 Correct 82 ms 20196 KB Output is correct
68 Correct 82 ms 20196 KB Output is correct
69 Correct 103 ms 20060 KB Output is correct
70 Correct 81 ms 20196 KB Output is correct
71 Correct 92 ms 20192 KB Output is correct
72 Correct 95 ms 20196 KB Output is correct
73 Correct 119 ms 31600 KB Output is correct
74 Correct 93 ms 31716 KB Output is correct
75 Correct 101 ms 21408 KB Output is correct
76 Correct 87 ms 21628 KB Output is correct
77 Correct 82 ms 19940 KB Output is correct
78 Correct 85 ms 20008 KB Output is correct
79 Correct 79 ms 19988 KB Output is correct
80 Correct 93 ms 19940 KB Output is correct
81 Correct 82 ms 20160 KB Output is correct
82 Correct 94 ms 20172 KB Output is correct
83 Correct 94 ms 25128 KB Output is correct
84 Correct 106 ms 27456 KB Output is correct
85 Correct 93 ms 27112 KB Output is correct
86 Correct 105 ms 21492 KB Output is correct
87 Correct 84 ms 20768 KB Output is correct
88 Correct 84 ms 20852 KB Output is correct
89 Correct 80 ms 20960 KB Output is correct
90 Correct 80 ms 20728 KB Output is correct
91 Correct 98 ms 21072 KB Output is correct
92 Correct 79 ms 21292 KB Output is correct
93 Correct 86 ms 23640 KB Output is correct
94 Correct 81 ms 25112 KB Output is correct
95 Correct 101 ms 24272 KB Output is correct
96 Correct 80 ms 22016 KB Output is correct
97 Correct 88 ms 20752 KB Output is correct
98 Correct 78 ms 20196 KB Output is correct
99 Correct 76 ms 20200 KB Output is correct
100 Correct 81 ms 23112 KB Output is correct
101 Correct 87 ms 20964 KB Output is correct
102 Correct 76 ms 20440 KB Output is correct
103 Correct 89 ms 20528 KB Output is correct
104 Correct 75 ms 20668 KB Output is correct
105 Correct 110 ms 28444 KB Output is correct
106 Correct 66 ms 20708 KB Output is correct
107 Correct 63 ms 20676 KB Output is correct
108 Correct 105 ms 32488 KB Output is correct
109 Correct 61 ms 20880 KB Output is correct
110 Correct 99 ms 32852 KB Output is correct
111 Correct 77 ms 19936 KB Output is correct