답안 #654901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654901 2022-11-01T22:00:52 Z inksamurai Village (BOI20_village) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3fm6nhZ ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

signed main(){
_3fm6nhZ;
	int n;
	cin>>n;
	vec(vi) adj(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u-=1,v-=1;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int ans=0;
	vi ert(n);
	auto dfs=[&](auto self,int v,int par)->int{
		vi rbts;
		for(auto u:adj[v]){
			if(u==par) continue;
			int e=self(self,u,v);
			if(e){
				rbts.pb(u);
			}
		}
		for(int i=0;i<sz(rbts)-sz(rbts)%2;i+=2){
			ert[rbts[i]]=rbts[i+1];
			ert[rbts[i+1]]=rbts[i];
			ans+=4;
		}
		if(sz(rbts)%2){
			ert[v]=rbts.back();
			ert[rbts.back()]=v;
			ans+=2;
		}
		return (sz(rbts)%2)^1;
	};
	int e=dfs(dfs,0,-1);
	if(e){
		int v=0;
		map<int,int> mp;
		for(auto u:adj[v])mp[u]=1;
		for(auto u:adj[v]){
			int nxt=ert[u];
			if(mp[nxt]){
				ert[0]=u;
				ert[nxt]=0;
				break;
			}
		}
		if(!ert[0]){
			int u=adj[0][0];
			int nxt=ert[u];
			ert[0]=u;
			ert[nxt]=0;
			ans+=2;
		}
	}
	cout<<ans<<" "<<ans<<"\n";
	assert(sz(set<int>(ert.begin(),ert.end()))==n);
	rep(t,2){
		rep(i,n)cout<<ert[i]+1<<" ";
		print();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 0 ms 212 KB Partially correct
3 Correct 0 ms 212 KB Output is correct
4 Partially correct 0 ms 212 KB Partially correct
5 Partially correct 0 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Correct 0 ms 320 KB Output is correct
8 Partially correct 1 ms 212 KB Partially correct
9 Partially correct 1 ms 320 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 0 ms 212 KB Partially correct
3 Correct 0 ms 212 KB Output is correct
4 Partially correct 0 ms 212 KB Partially correct
5 Partially correct 0 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Correct 0 ms 320 KB Output is correct
8 Partially correct 1 ms 212 KB Partially correct
9 Partially correct 1 ms 320 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -