QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84320#5651. Parmigiana With SeafoodAlienCollapsarWA 2ms3344kbC++14916b2023-03-06 10:37:282023-03-06 10:37:32

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 10:37:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3344kb
  • [2023-03-06 10:37:28]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
const int Maxn=1e5+5;
struct adjacency_list{int nxt,t;}tr[Maxn<<1];
int h[Maxn],tot;
inline void add(int x,int y){
	tr[++tot]={h[x],y};h[x]=tot;
}
int  fv[Maxn];
int  deg[Maxn],cnt[Maxn];
bool vis[Maxn],cur[Maxn];
void dfs(int x,int fa){
	fv[x]=fa;cur[x]=cur[fa]^1;
	for(int i=h[x];i;i=tr[i].nxt){
		int y=tr[i].t;if(y==fa)continue;
		dfs(y,x);
	}
}
int main(){
	int n;cin>>n;
	if(~n&1){cout<<n<<'\n';return 0;}
	for(int i=2;i<=n;++i){
		int x,y;cin>>x>>y;
		add(x,y);++deg[x];
		add(y,x);++deg[y];
	}
	dfs(n,0);vis[n]=1;
	for(int i=n;i;--i){
		if(deg[i]==1||!cur[i]){
			cout<<i<<'\n';return 0;
		}
		int x=i;
		for(;vis[x];x=fv[x]){
			++cnt[x],++cnt[fv[x]];
			vis[x]=1;
		}
		for(int j=1;j<=n;++j)cout<<cnt[j]<<" \n"[j==n];
		if(cnt[x]>2&&cur[x]){
			cout<<i<<'\n';return 0;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3324kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3344kb

input:

5
1 5
5 3
3 4
4 2

output:

0 0 0 0 1
0 0 0 0 1
3

result:

wrong answer 1st lines differ - expected: '3', found: '0 0 0 0 1'