답안 #496710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496710 2021-12-22T02:24:01 Z jamezzz Power Plant (JOI20_power) C++17
100 / 100
164 ms 25088 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}

inline int rd(){
    int x=0;
    char ch=getchar_unlocked();
    while(ch<'0'||ch>'9')ch=getchar_unlocked();
    while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar_unlocked();
	}
    return x;
}

#define maxn 200005

int n,a,b,ans;
vi AL[maxn];
char s[maxn];

int dfs(int u,int p){
	int v0=0,v1=0,sm=0,mx=0;
	for(int v:AL[u]){
		if(v==p)continue;
		int tmp=dfs(v,u);
		sm+=max(tmp,0);
		mx=max(mx,tmp);
	}
	int t=(s[u-1]-'0');
	v0=max(sm-t,mx+t);//first one
	v1=max(sm-t,t);//>1 on top
	ans=max(ans,max(v0,v1));
	return v1;
}

int main(){
	sf("%d",&n);
	for(int i=1;i<n;++i){
		sf("%d%d",&a,&b);
		AL[a].pb(b);
		AL[b].pb(a);
	}
	sf(" %s",&s);
	dfs(1,1);
	pf("%d\n",ans);
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:85:8: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[200005]' [-Wformat=]
   85 |  sf(" %s",&s);
      |       ~^  ~~
      |        |  |
      |        |  char (*)[200005]
      |        char*
power.cpp:79:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  sf("%d",&n);
      |    ^
power.cpp:81:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |   sf("%d%d",&a,&b);
      |     ^
power.cpp:85:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |  sf(" %s",&s);
      |    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5000 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4984 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 2 ms 5004 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 2 ms 4996 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5000 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4984 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 2 ms 5004 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 2 ms 4996 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 4 ms 5008 KB Output is correct
27 Correct 4 ms 5012 KB Output is correct
28 Correct 5 ms 5068 KB Output is correct
29 Correct 3 ms 5060 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 4996 KB Output is correct
38 Correct 5 ms 4988 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 4 ms 4996 KB Output is correct
44 Correct 3 ms 5068 KB Output is correct
45 Correct 3 ms 5012 KB Output is correct
46 Correct 4 ms 5012 KB Output is correct
47 Correct 3 ms 5072 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 5 ms 5068 KB Output is correct
51 Correct 3 ms 5016 KB Output is correct
52 Correct 4 ms 5032 KB Output is correct
53 Correct 4 ms 5012 KB Output is correct
54 Correct 3 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 3 ms 5068 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5068 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 5 ms 5140 KB Output is correct
63 Correct 3 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5000 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5000 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4984 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 2 ms 5004 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 2 ms 4996 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 4 ms 5008 KB Output is correct
27 Correct 4 ms 5012 KB Output is correct
28 Correct 5 ms 5068 KB Output is correct
29 Correct 3 ms 5060 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 4996 KB Output is correct
38 Correct 5 ms 4988 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 4 ms 4996 KB Output is correct
44 Correct 3 ms 5068 KB Output is correct
45 Correct 3 ms 5012 KB Output is correct
46 Correct 4 ms 5012 KB Output is correct
47 Correct 3 ms 5072 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 5 ms 5068 KB Output is correct
51 Correct 3 ms 5016 KB Output is correct
52 Correct 4 ms 5032 KB Output is correct
53 Correct 4 ms 5012 KB Output is correct
54 Correct 3 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 3 ms 5068 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5068 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 5 ms 5140 KB Output is correct
63 Correct 3 ms 5012 KB Output is correct
64 Correct 126 ms 14220 KB Output is correct
65 Correct 133 ms 14208 KB Output is correct
66 Correct 141 ms 14152 KB Output is correct
67 Correct 118 ms 14200 KB Output is correct
68 Correct 131 ms 14244 KB Output is correct
69 Correct 136 ms 14196 KB Output is correct
70 Correct 126 ms 14240 KB Output is correct
71 Correct 145 ms 14168 KB Output is correct
72 Correct 150 ms 14288 KB Output is correct
73 Correct 137 ms 24252 KB Output is correct
74 Correct 154 ms 24440 KB Output is correct
75 Correct 140 ms 14116 KB Output is correct
76 Correct 132 ms 14072 KB Output is correct
77 Correct 144 ms 14048 KB Output is correct
78 Correct 151 ms 14132 KB Output is correct
79 Correct 130 ms 14064 KB Output is correct
80 Correct 116 ms 14096 KB Output is correct
81 Correct 120 ms 14492 KB Output is correct
82 Correct 136 ms 14292 KB Output is correct
83 Correct 144 ms 18316 KB Output is correct
84 Correct 138 ms 20024 KB Output is correct
85 Correct 131 ms 19748 KB Output is correct
86 Correct 118 ms 15300 KB Output is correct
87 Correct 126 ms 14768 KB Output is correct
88 Correct 123 ms 15248 KB Output is correct
89 Correct 107 ms 15284 KB Output is correct
90 Correct 129 ms 15112 KB Output is correct
91 Correct 143 ms 15440 KB Output is correct
92 Correct 129 ms 15612 KB Output is correct
93 Correct 119 ms 17472 KB Output is correct
94 Correct 119 ms 18740 KB Output is correct
95 Correct 106 ms 17920 KB Output is correct
96 Correct 109 ms 16396 KB Output is correct
97 Correct 129 ms 15088 KB Output is correct
98 Correct 109 ms 14812 KB Output is correct
99 Correct 133 ms 14532 KB Output is correct
100 Correct 130 ms 17180 KB Output is correct
101 Correct 142 ms 15416 KB Output is correct
102 Correct 116 ms 14824 KB Output is correct
103 Correct 117 ms 14796 KB Output is correct
104 Correct 92 ms 15012 KB Output is correct
105 Correct 164 ms 21752 KB Output is correct
106 Correct 81 ms 14736 KB Output is correct
107 Correct 88 ms 14760 KB Output is correct
108 Correct 150 ms 24928 KB Output is correct
109 Correct 78 ms 14988 KB Output is correct
110 Correct 158 ms 25088 KB Output is correct
111 Correct 127 ms 14140 KB Output is correct