QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123579#5651. Parmigiana With SeafoodzswzswzswWA 29ms10096kbC++14984b2023-07-12 23:14:222023-07-12 23:14:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-12 23:14:26]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:10096kb
  • [2023-07-12 23:14:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long read(void)
{
	char ch=getchar();long long sum=0;bool f=0;
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')f=1,ch=getchar();
	while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=getchar();
	if(f)sum=-sum;return sum;
}
const int N=101000;
int n;
bool tg[N];
int dep[N],is[N];
vector<int>G[N];
bool DFS(int u,int f){
	bool fl=1;
	int cnt=0;is[u]=tg[u];dep[u]=dep[f]+1;
	if(tg[u]&&((dep[u]-1)&1))return 0;
	for(int v:G[u])if(v!=f){
		fl&=DFS(v,u);cnt+=is[v];
		is[u]|=is[v];
	}
	if(u!=n&&dep[u]%2==0&&cnt>=2)fl=0;
	if(u==n&&cnt>=3)fl=0;
	return fl;
	
}
bool chk(int t){
	for(int i=1;i<=n;i++)tg[i]=(i>=t),is[i]=0;
	return DFS(n,0)^1;
}
int main()
{
	n=read();
	for(int i=1,x,y;i<=n-1;i++)x=read(),y=read(),G[x].push_back(y),G[y].push_back(x);
	if(!(n&1))return cout<<n,0;
	int L=1,R=n;
	while(L<R){
		int mid=(L+R+1)>>1;
		if(chk(mid))L=mid;
		else R=mid-1;
	}cout<<L;
	return 0;
	
}

詳細信息

Test #1:

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

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6344kb

input:

5
1 5
5 3
3 4
4 2

output:

3

result:

ok single line: '3'

Test #3:

score: -100
Wrong Answer
time: 29ms
memory: 10096kb

input:

99999
81856 39633
81856 94012
99999 43062
99946 220
81856 46131
99933 36505
99939 35662
99952 70971
99999 3275
99938 58416
99976 66658
99991 87922
81856 80992
99933 6392
99951 41047
99970 54115
81856 38150
99934 73554
81856 64578
81856 18576
99951 67996
99938 84479
81856 39617
99999 18664
99946 2505...

output:

99997

result:

wrong answer 1st lines differ - expected: '99925', found: '99997'