Submission #48249553


Source Code Expand

// LUOGU_RID: 138554573
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define eb emplace_back
#define File(filename) freopen(filename ".in","r",stdin),freopen(filename ".out","w",stdout)

#ifdef EXODUS
	#define Debug(...) fprintf(stderr,__VA_ARGS__)
#else
	#define Debug(...) 0
#endif

//=========================================================================================================
// Something about IO

template<typename T>
void read(T &x){
	x=0;T flg=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')flg=-1;ch=getchar();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x*=flg;
}
template<typename T,typename... Args>
void read(T &x,Args &...args){read(x),read(args...);}

//=========================================================================================================
// Define the global variables here.

bool membg=0;
constexpr int N=5e3+7;

int n,deg[N],p[N];
vector<int>g[N];
bool memed=0;

//=========================================================================================================
// Code here.


void solve(){
	read(n);
	for(int i=1,u,v;i<n;i++)read(u,v),g[u].eb(v),g[v].eb(u),deg[u]++,deg[v]++;
	queue<int>q;
	for(int i=1;i<=n;i++)if(deg[i]==1)q.emplace(i);
	while(q.size()>=2){
		int u=q.front();q.pop();
		int v=q.front();q.pop();
		p[u]=v,p[v]=u;
		for(auto w:g[u])if((--deg[w])==1)q.emplace(w);
		for(auto w:g[v])if((--deg[w])==1)q.emplace(w);
	}
	if(!q.empty())p[q.front()]=q.front();
	for(int i=1;i<=n;i++)printf("%d ",p[i]);
	printf("\n");
	return;
}


//=========================================================================================================

int main(){
	Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
	int timbg=clock();
	int T=1;
	while(T--)solve();
	int timed=clock();
	Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
	fflush(stdout);
	return 0;
}

Submission Info

Submission Time
Task C - Tree and LCS
User EXODUS
Language C++ 17 (gcc 12.2)
Score 600
Code Size 2120 Byte
Status AC
Exec Time 2 ms
Memory 4264 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
   18 |         #define Debug(...) 0
      |                            ^
Main.cpp:71:9: note: in expansion of macro ‘Debug’
   71 |         Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
      |         ^~~~~
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
   18 |         #define Debug(...) 0
      |                            ^
Main.cpp:76:9: note: in expansion of macro ‘Debug’
   76 |         Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
      |         ^~~~~
Main.cpp:72:13: warning: unused variable ‘timbg’ [-Wunused-variable]
   72 |         int timbg=clock();
      |             ^~~~~
Main.cpp:75:13: warning: unused variable ‘timed’ [-Wunused-variable]
   75 |         int timed=clock();
      |             ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 37
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt, 02_large_07.txt, 02_large_08.txt, 02_large_09.txt, 02_large_10.txt, 03_star_01.txt, 03_star_02.txt, 03_star_03.txt, 03_star_04.txt, 03_star_05.txt, 04_path_01.txt, 04_path_02.txt, 04_path_03.txt, 04_path_04.txt, 04_path_05.txt, 05_caterpillar_01.txt, 05_caterpillar_02.txt, 05_caterpillar_03.txt, 05_caterpillar_04.txt, 05_caterpillar_05.txt, 06_binary_01.txt, 06_binary_02.txt, 06_binary_03.txt, 06_binary_04.txt, 06_binary_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3844 KiB
00_sample_02.txt AC 1 ms 3916 KiB
01_small_01.txt AC 1 ms 3996 KiB
01_small_02.txt AC 1 ms 4064 KiB
01_small_03.txt AC 1 ms 3860 KiB
01_small_04.txt AC 1 ms 3884 KiB
01_small_05.txt AC 1 ms 3860 KiB
02_large_01.txt AC 2 ms 3960 KiB
02_large_02.txt AC 2 ms 4264 KiB
02_large_03.txt AC 2 ms 4156 KiB
02_large_04.txt AC 2 ms 4192 KiB
02_large_05.txt AC 2 ms 4088 KiB
02_large_06.txt AC 2 ms 3924 KiB
02_large_07.txt AC 2 ms 4172 KiB
02_large_08.txt AC 2 ms 4260 KiB
02_large_09.txt AC 2 ms 3976 KiB
02_large_10.txt AC 2 ms 3980 KiB
03_star_01.txt AC 2 ms 4056 KiB
03_star_02.txt AC 2 ms 4056 KiB
03_star_03.txt AC 2 ms 4220 KiB
03_star_04.txt AC 2 ms 4040 KiB
03_star_05.txt AC 2 ms 4016 KiB
04_path_01.txt AC 2 ms 3936 KiB
04_path_02.txt AC 2 ms 4064 KiB
04_path_03.txt AC 2 ms 4080 KiB
04_path_04.txt AC 2 ms 4084 KiB
04_path_05.txt AC 2 ms 4028 KiB
05_caterpillar_01.txt AC 2 ms 4056 KiB
05_caterpillar_02.txt AC 2 ms 4080 KiB
05_caterpillar_03.txt AC 2 ms 4188 KiB
05_caterpillar_04.txt AC 2 ms 3912 KiB
05_caterpillar_05.txt AC 2 ms 3956 KiB
06_binary_01.txt AC 2 ms 3992 KiB
06_binary_02.txt AC 1 ms 3852 KiB
06_binary_03.txt AC 2 ms 4136 KiB
06_binary_04.txt AC 2 ms 4120 KiB
06_binary_05.txt AC 2 ms 4048 KiB