답안 #940214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940214 2024-03-07T06:41:05 Z pcc Village (BOI20_village) C++14
0 / 100
3 ms 4188 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];
	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(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(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 'int main()':
Village.cpp:100:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  100 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:100:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  100 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
Village.cpp:101:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  101 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:101:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  101 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 4188 KB Partially correct
2 Partially correct 1 ms 4188 KB Partially correct
3 Partially correct 1 ms 4188 KB Partially correct
4 Partially correct 1 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 1 ms 4188 KB Partially correct
9 Partially correct 1 ms 4188 KB Partially correct
10 Partially correct 3 ms 4188 KB Partially correct
11 Partially correct 1 ms 4188 KB Partially correct
12 Partially correct 1 ms 4188 KB Partially correct
13 Incorrect 1 ms 4188 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 4188 KB Partially correct
2 Partially correct 1 ms 4188 KB Partially correct
3 Partially correct 1 ms 4188 KB Partially correct
4 Partially correct 1 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 1 ms 4188 KB Partially correct
9 Partially correct 1 ms 4188 KB Partially correct
10 Partially correct 3 ms 4188 KB Partially correct
11 Partially correct 1 ms 4188 KB Partially correct
12 Partially correct 1 ms 4188 KB Partially correct
13 Incorrect 1 ms 4188 KB Output isn't correct
14 Halted 0 ms 0 KB -