답안 #940159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940159 2024-03-07T06:14:12 Z pcc Village (BOI20_village) C++14
0 / 100
1 ms 4440 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{
	vector<pii> ansv;
	ll ans;
	ll dp[mxn];
	int mx[mxn];
	int dep[mxn];
	void dfs(int now,int par){
		vector<int> need;
		dp[now] = 1;
		for(auto nxt:tree[now]){
			if(nxt == par)continue;
			dep[nxt] = dep[now]+1;
			dfs(nxt,now);
			if(dp[nxt])need.push_back(nxt);
		}
		if(now == par){
			dp[now] = 0;
			if(need.empty()){
				ans += 2;
				int a = tree[now][0],b = mx[a];
				mx[b] = now;
				mx[now] = a;
			}
			else if((need.size()+1)%2==0){
				ans += 2;
				int a = need.back();
				need.pop_back();
				mx[a] = now;
				mx[now] = a;
			}
			else{
				ans += 4;
				int a = need.back();need.pop_back();
				int b = need.back();need.pop_back();
				mx[a] = b;
				mx[b] = now;
				mx[now] = a;
			}
		}
		while(need.size()>=2){
			ans += 4;
			int a = need.end()[-1],b = need.end()[-2];
			need.pop_back();
			need.pop_back();
			mx[a] = b,mx[b] = a;
		}
		if(dp[now]&&!need.empty()){
			ans += 2;
			int a = need.back();
			need.pop_back();
			dp[now] = 0;
			mx[now] = a;
			mx[a] = now;
		}
		return;
	}
	void solve(){
		dfs(1,1);
		for(int i = 1;i<=N;i++){
			ansv.push_back({i,mx[i]});
		}
		return;
	}
}

namespace S2{
	vector<pii> ansv;
	int mx[mxn];
	ll ans;
	void solve(){
		ansv = vector<pii>(N,pii(1,1));
	}
}

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(auto &i:S1::ansv)cout<<i.fs<<' ';cout<<'\n';
	for(auto &i:S1::ansv)cout<<i.sc<<' ';cout<<'\n';
	for(auto &i:S2::ansv)cout<<i.fs<<' ';cout<<'\n';
	for(auto &i:S2::ansv)cout<<i.sc<<' ';cout<<'\n';
	return 0;
}

Compilation message

Village.cpp: In function 'int main()':
Village.cpp:103:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  103 |  for(auto &i:S1::ansv)cout<<i.fs<<' ';cout<<'\n';
      |  ^~~
Village.cpp:103:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  103 |  for(auto &i:S1::ansv)cout<<i.fs<<' ';cout<<'\n';
      |                                       ^~~~
Village.cpp:104:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  104 |  for(auto &i:S1::ansv)cout<<i.sc<<' ';cout<<'\n';
      |  ^~~
Village.cpp:104:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  104 |  for(auto &i:S1::ansv)cout<<i.sc<<' ';cout<<'\n';
      |                                       ^~~~
Village.cpp:105:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  105 |  for(auto &i:S2::ansv)cout<<i.fs<<' ';cout<<'\n';
      |  ^~~
Village.cpp:105:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  105 |  for(auto &i:S2::ansv)cout<<i.fs<<' ';cout<<'\n';
      |                                       ^~~~
Village.cpp:106:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  106 |  for(auto &i:S2::ansv)cout<<i.sc<<' ';cout<<'\n';
      |  ^~~
Village.cpp:106:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  106 |  for(auto &i:S2::ansv)cout<<i.sc<<' ';cout<<'\n';
      |                                       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -