답안 #940384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940384 2024-03-07T08:45:49 Z pcc Village (BOI20_village) C++14
50 / 100
57 ms 21584 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 1e5+10;
vector<int> tree[mxn];
int N;

namespace S1{
	ll ans;
	ll dp[mxn];
	int mx[mxn];
	void dfs(int now,int par){
		vector<int> need;
		dp[now] = 1;
		for(auto nxt:tree[now]){
			if(nxt == par)continue;
			dfs(nxt,now);
			if(dp[nxt])need.push_back(nxt);
		}
		if(need.size()>=2){
			dp[now] = 0;
			ans += need.size()*2;
			for(int i = 1;i<need.size();i++){
				mx[need[i-1]] = need[i];
			}
			mx[need.back()] = now;
			mx[now] = need[0];
			need.clear();
		}
		else if(need.size() == 1){
			dp[now] = 0;
			ans += 2;
			int a = need[0];
			mx[now] = a;
			mx[a] = now;
		}
		if(now==par&&dp[now]){
			ans += 2;
			int a = tree[now][0],b = mx[a];
			while(mx[b] != a)b = mx[b];
			mx[now] = a;
			mx[b] = now;
		}
		return;
	}
	void solve(){
		dfs(1,1);
		return;
	}
}

namespace S2{
	int mx[mxn];
	ll ans;
	void solve(){
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	for(int i = 1;i<N;i++){
		int a,b;
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	S1::solve();
	S2::solve();
	cout<<S1::ans<<' '<<S2::ans<<'\n';
	for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
	for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
	return 0;
}

Compilation message

Village.cpp: In function 'void S1::dfs(int, int)':
Village.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for(int i = 1;i<need.size();i++){
      |                  ~^~~~~~~~~~~~
Village.cpp: In function 'int main()':
Village.cpp:79:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   79 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:79:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   79 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
Village.cpp:80:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   80 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:80:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 4184 KB Partially correct
2 Partially correct 1 ms 4188 KB Partially correct
3 Partially correct 1 ms 4188 KB Partially correct
4 Partially correct 2 ms 4188 KB Partially correct
5 Partially correct 1 ms 4188 KB Partially correct
6 Partially correct 1 ms 4188 KB Partially correct
7 Partially correct 1 ms 4188 KB Partially correct
8 Partially correct 2 ms 4196 KB Partially correct
9 Partially correct 1 ms 4184 KB Partially correct
10 Partially correct 2 ms 4188 KB Partially correct
11 Partially correct 1 ms 4188 KB Partially correct
12 Partially correct 2 ms 3976 KB Partially correct
13 Partially correct 2 ms 4188 KB Partially correct
14 Partially correct 1 ms 4188 KB Partially correct
15 Partially correct 2 ms 4204 KB Partially correct
16 Partially correct 2 ms 4188 KB Partially correct
17 Partially correct 2 ms 4188 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 4188 KB Partially correct
2 Partially correct 2 ms 4188 KB Partially correct
3 Partially correct 2 ms 4188 KB Partially correct
4 Partially correct 2 ms 4188 KB Partially correct
5 Partially correct 2 ms 4188 KB Partially correct
6 Partially correct 2 ms 4188 KB Partially correct
7 Partially correct 2 ms 4188 KB Partially correct
8 Partially correct 2 ms 4188 KB Partially correct
9 Partially correct 2 ms 4440 KB Partially correct
10 Partially correct 2 ms 4208 KB Partially correct
11 Partially correct 2 ms 4200 KB Partially correct
12 Partially correct 2 ms 4188 KB Partially correct
13 Partially correct 2 ms 4188 KB Partially correct
14 Partially correct 2 ms 4188 KB Partially correct
15 Partially correct 2 ms 4188 KB Partially correct
16 Partially correct 2 ms 4204 KB Partially correct
17 Partially correct 2 ms 4188 KB Partially correct
18 Partially correct 2 ms 4188 KB Partially correct
19 Partially correct 2 ms 4188 KB Partially correct
20 Partially correct 2 ms 4188 KB Partially correct
21 Partially correct 2 ms 4188 KB Partially correct
22 Partially correct 2 ms 4184 KB Partially correct
23 Partially correct 2 ms 4188 KB Partially correct
24 Partially correct 2 ms 4204 KB Partially correct
25 Partially correct 2 ms 4188 KB Partially correct
26 Partially correct 2 ms 4188 KB Partially correct
27 Partially correct 2 ms 4188 KB Partially correct
28 Partially correct 2 ms 4188 KB Partially correct
29 Partially correct 2 ms 4188 KB Partially correct
30 Partially correct 2 ms 4256 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 4184 KB Partially correct
2 Partially correct 1 ms 4188 KB Partially correct
3 Partially correct 1 ms 4188 KB Partially correct
4 Partially correct 2 ms 4188 KB Partially correct
5 Partially correct 1 ms 4188 KB Partially correct
6 Partially correct 1 ms 4188 KB Partially correct
7 Partially correct 1 ms 4188 KB Partially correct
8 Partially correct 2 ms 4196 KB Partially correct
9 Partially correct 1 ms 4184 KB Partially correct
10 Partially correct 2 ms 4188 KB Partially correct
11 Partially correct 1 ms 4188 KB Partially correct
12 Partially correct 2 ms 3976 KB Partially correct
13 Partially correct 2 ms 4188 KB Partially correct
14 Partially correct 1 ms 4188 KB Partially correct
15 Partially correct 2 ms 4204 KB Partially correct
16 Partially correct 2 ms 4188 KB Partially correct
17 Partially correct 2 ms 4188 KB Partially correct
18 Partially correct 2 ms 4188 KB Partially correct
19 Partially correct 2 ms 4188 KB Partially correct
20 Partially correct 2 ms 4188 KB Partially correct
21 Partially correct 2 ms 4188 KB Partially correct
22 Partially correct 2 ms 4188 KB Partially correct
23 Partially correct 2 ms 4188 KB Partially correct
24 Partially correct 2 ms 4188 KB Partially correct
25 Partially correct 2 ms 4188 KB Partially correct
26 Partially correct 2 ms 4440 KB Partially correct
27 Partially correct 2 ms 4208 KB Partially correct
28 Partially correct 2 ms 4200 KB Partially correct
29 Partially correct 2 ms 4188 KB Partially correct
30 Partially correct 2 ms 4188 KB Partially correct
31 Partially correct 2 ms 4188 KB Partially correct
32 Partially correct 2 ms 4188 KB Partially correct
33 Partially correct 2 ms 4204 KB Partially correct
34 Partially correct 2 ms 4188 KB Partially correct
35 Partially correct 2 ms 4188 KB Partially correct
36 Partially correct 2 ms 4188 KB Partially correct
37 Partially correct 2 ms 4188 KB Partially correct
38 Partially correct 2 ms 4188 KB Partially correct
39 Partially correct 2 ms 4184 KB Partially correct
40 Partially correct 2 ms 4188 KB Partially correct
41 Partially correct 2 ms 4204 KB Partially correct
42 Partially correct 2 ms 4188 KB Partially correct
43 Partially correct 2 ms 4188 KB Partially correct
44 Partially correct 2 ms 4188 KB Partially correct
45 Partially correct 2 ms 4188 KB Partially correct
46 Partially correct 2 ms 4188 KB Partially correct
47 Partially correct 2 ms 4256 KB Partially correct
48 Partially correct 35 ms 9272 KB Partially correct
49 Partially correct 45 ms 9792 KB Partially correct
50 Partially correct 38 ms 9560 KB Partially correct
51 Partially correct 37 ms 8520 KB Partially correct
52 Partially correct 38 ms 9712 KB Partially correct
53 Partially correct 33 ms 8928 KB Partially correct
54 Partially correct 21 ms 12372 KB Partially correct
55 Partially correct 50 ms 21584 KB Partially correct
56 Partially correct 55 ms 15504 KB Partially correct
57 Partially correct 55 ms 13648 KB Partially correct
58 Partially correct 40 ms 11604 KB Partially correct
59 Partially correct 41 ms 9812 KB Partially correct
60 Partially correct 33 ms 9876 KB Partially correct
61 Partially correct 41 ms 10252 KB Partially correct
62 Partially correct 35 ms 10068 KB Partially correct
63 Partially correct 32 ms 9740 KB Partially correct
64 Partially correct 35 ms 10064 KB Partially correct
65 Partially correct 51 ms 10156 KB Partially correct
66 Partially correct 33 ms 9812 KB Partially correct
67 Partially correct 35 ms 8692 KB Partially correct
68 Partially correct 27 ms 9064 KB Partially correct
69 Partially correct 35 ms 10072 KB Partially correct
70 Partially correct 35 ms 9808 KB Partially correct
71 Partially correct 26 ms 8588 KB Partially correct
72 Partially correct 36 ms 8820 KB Partially correct
73 Partially correct 32 ms 10068 KB Partially correct
74 Partially correct 35 ms 9516 KB Partially correct
75 Partially correct 57 ms 9504 KB Partially correct
76 Partially correct 49 ms 9556 KB Partially correct
77 Partially correct 34 ms 9812 KB Partially correct
78 Partially correct 27 ms 7760 KB Partially correct
79 Partially correct 28 ms 8532 KB Partially correct
80 Partially correct 38 ms 9564 KB Partially correct
81 Partially correct 52 ms 9812 KB Partially correct
82 Partially correct 35 ms 9812 KB Partially correct