답안 #763084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763084 2023-06-22T03:11:53 Z vjudge1 Power Plant (JOI20_power) C++14
47 / 100
110 ms 24908 KB
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//using namespace __gnu_pbds;
using namespace std;

//#define int long long
//#define double long double
#define Fi first
#define Se second
#define Rep(i,a,b) for (int i=a;i<=b;++i)
#define Repu(i,b,a) for (int i=b;i>=a;--i)
#define pb push_back
#define ms(a,i) memset(a,i,sizeof(a))
#define sz size()
#define mp make_pair
#define endl '\n'
#define sef setprecision(12)<<fixed
#define cer cout<<"cak"<<endl;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<double> va;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<va> vva;

//const double EPS=1e-9;
const double PI=acos(-1);
//const int oo=1e18;
const int MN=2e5+5;
const int mod=1e9+7;

using cd=complex<double>;

//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> index_set;

int n;
vi adj[MN];

char s[MN];

int siz[MN];

void dfs(int u,int pre) {
	int sum = 0;
	for(int v:adj[u]) {
		if(v==pre) continue;
		dfs(v,u);
		sum += siz[v];
	}

	if(s[u]=='1') {
		sum--;
		siz[u] = max(1,sum);
	}
	else {
		siz[u] = sum;
	}
}

void solve(int u) {
	for(int v:adj[u]) {
		dfs(v,u);
		siz[u] = max(siz[u], siz[v]);
	}
	siz[u]++;
}

void process(int u) {
	for(int v:adj[u]) {
		dfs(v,u);
		siz[u] += siz[v];
	}
}

signed main() {
	//freopen(".inp","r",stdin); freopen(".out","w",stdout);

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin>>n;
	Rep(i,1,n-1) {
		int u,v; cin>>u>>v;
		adj[u].pb(v); adj[v].pb(u);
	}

	Rep(i,1,n) cin>>s[i];

	int ans=0;

	if(n<=2000) {
		Rep(i,1,n) {
			if(s[i]=='1') {
				Rep(i,1,n) siz[i] = 0;
				solve(i);
				//cout<<"Root at "<<i<<endl;
				//Rep(i,1,n) cout<<siz[i]<<" ";
				//cout<<endl;
				ans=max(ans,siz[i]);
			}
			else {
				Rep(i,1,n) siz[i] = 0;
				process(i);
				ans=max(ans,siz[i]);
			}
		}

		cout<<ans;

		return 0;
	}

	Rep(i,1,n) {
		if(s[i]=='1') {
			Rep(i,1,n) siz[i] = 0;
			solve(i);
			ans=max(ans,siz[i]);
			break;
		}
	}

	Rep(i,1,n) {
		if(s[i]=='0') {
			Rep(i,1,n) siz[i] = 0;
			process(i);
			ans=max(ans,siz[i]);
			break;
		}
	}

	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 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 2 ms 4948 KB Output is correct
8 Correct 2 ms 5016 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 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 3 ms 5024 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 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 2 ms 4948 KB Output is correct
8 Correct 2 ms 5016 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 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 3 ms 5024 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 37 ms 5076 KB Output is correct
23 Correct 36 ms 5092 KB Output is correct
24 Correct 36 ms 5076 KB Output is correct
25 Correct 36 ms 5084 KB Output is correct
26 Correct 35 ms 5076 KB Output is correct
27 Correct 35 ms 5076 KB Output is correct
28 Correct 35 ms 5076 KB Output is correct
29 Correct 62 ms 5240 KB Output is correct
30 Correct 54 ms 5236 KB Output is correct
31 Correct 32 ms 5076 KB Output is correct
32 Correct 32 ms 5076 KB Output is correct
33 Correct 38 ms 5084 KB Output is correct
34 Correct 39 ms 5100 KB Output is correct
35 Correct 42 ms 5084 KB Output is correct
36 Correct 36 ms 5076 KB Output is correct
37 Correct 30 ms 5076 KB Output is correct
38 Correct 41 ms 5092 KB Output is correct
39 Correct 46 ms 5076 KB Output is correct
40 Correct 47 ms 5076 KB Output is correct
41 Correct 42 ms 5076 KB Output is correct
42 Correct 41 ms 5076 KB Output is correct
43 Correct 38 ms 5076 KB Output is correct
44 Correct 38 ms 5080 KB Output is correct
45 Correct 36 ms 5076 KB Output is correct
46 Correct 36 ms 5116 KB Output is correct
47 Correct 36 ms 5108 KB Output is correct
48 Correct 38 ms 5076 KB Output is correct
49 Correct 38 ms 5164 KB Output is correct
50 Correct 39 ms 5144 KB Output is correct
51 Correct 38 ms 5076 KB Output is correct
52 Correct 37 ms 5092 KB Output is correct
53 Correct 33 ms 5076 KB Output is correct
54 Correct 37 ms 5076 KB Output is correct
55 Correct 37 ms 5108 KB Output is correct
56 Correct 26 ms 5076 KB Output is correct
57 Correct 51 ms 5204 KB Output is correct
58 Correct 22 ms 5112 KB Output is correct
59 Correct 24 ms 5112 KB Output is correct
60 Correct 49 ms 5204 KB Output is correct
61 Correct 21 ms 5076 KB Output is correct
62 Correct 55 ms 5236 KB Output is correct
63 Correct 30 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 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 2 ms 4948 KB Output is correct
8 Correct 2 ms 5016 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 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 3 ms 5024 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 37 ms 5076 KB Output is correct
23 Correct 36 ms 5092 KB Output is correct
24 Correct 36 ms 5076 KB Output is correct
25 Correct 36 ms 5084 KB Output is correct
26 Correct 35 ms 5076 KB Output is correct
27 Correct 35 ms 5076 KB Output is correct
28 Correct 35 ms 5076 KB Output is correct
29 Correct 62 ms 5240 KB Output is correct
30 Correct 54 ms 5236 KB Output is correct
31 Correct 32 ms 5076 KB Output is correct
32 Correct 32 ms 5076 KB Output is correct
33 Correct 38 ms 5084 KB Output is correct
34 Correct 39 ms 5100 KB Output is correct
35 Correct 42 ms 5084 KB Output is correct
36 Correct 36 ms 5076 KB Output is correct
37 Correct 30 ms 5076 KB Output is correct
38 Correct 41 ms 5092 KB Output is correct
39 Correct 46 ms 5076 KB Output is correct
40 Correct 47 ms 5076 KB Output is correct
41 Correct 42 ms 5076 KB Output is correct
42 Correct 41 ms 5076 KB Output is correct
43 Correct 38 ms 5076 KB Output is correct
44 Correct 38 ms 5080 KB Output is correct
45 Correct 36 ms 5076 KB Output is correct
46 Correct 36 ms 5116 KB Output is correct
47 Correct 36 ms 5108 KB Output is correct
48 Correct 38 ms 5076 KB Output is correct
49 Correct 38 ms 5164 KB Output is correct
50 Correct 39 ms 5144 KB Output is correct
51 Correct 38 ms 5076 KB Output is correct
52 Correct 37 ms 5092 KB Output is correct
53 Correct 33 ms 5076 KB Output is correct
54 Correct 37 ms 5076 KB Output is correct
55 Correct 37 ms 5108 KB Output is correct
56 Correct 26 ms 5076 KB Output is correct
57 Correct 51 ms 5204 KB Output is correct
58 Correct 22 ms 5112 KB Output is correct
59 Correct 24 ms 5112 KB Output is correct
60 Correct 49 ms 5204 KB Output is correct
61 Correct 21 ms 5076 KB Output is correct
62 Correct 55 ms 5236 KB Output is correct
63 Correct 30 ms 5076 KB Output is correct
64 Correct 62 ms 12340 KB Output is correct
65 Correct 75 ms 12268 KB Output is correct
66 Correct 87 ms 12372 KB Output is correct
67 Correct 85 ms 12288 KB Output is correct
68 Correct 75 ms 12292 KB Output is correct
69 Correct 77 ms 12348 KB Output is correct
70 Correct 72 ms 12356 KB Output is correct
71 Correct 73 ms 12228 KB Output is correct
72 Correct 96 ms 12360 KB Output is correct
73 Correct 81 ms 24908 KB Output is correct
74 Correct 110 ms 24884 KB Output is correct
75 Correct 65 ms 12236 KB Output is correct
76 Correct 68 ms 12236 KB Output is correct
77 Incorrect 96 ms 12204 KB Output isn't correct
78 Halted 0 ms 0 KB -