请求添加 Hack 数据
查看原帖
请求添加 Hack 数据
206875
pref_ctrl27楼主2022/12/11 19:10

如下错解能够 AC:

#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
char buf[1<<14],*p1=buf,*p2=buf;
#define GetC() ((p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<14,stdin),p1==p2)?EOF:*p1++)
struct Ios{}io;
template <typename _tp>
Ios &operator >>(Ios &in,_tp &x){
	x=0;int w=0;char c=GetC();
	for(;!isdigit(c);w|=c=='-',c=GetC());
	for(;isdigit(c);x=x*10+(c^'0'),c=GetC());
	if(w) x=-x;
	return in;
}
const int N=1e5+5;
struct EDGE{int nxt,to;}e[N<<1];
int head[N],tot;
void add(int from,int to){
	e[++tot].nxt=head[from];
	e[tot].to=to;
	head[from]=tot;
}
bool is;
int dfs(int u,int fa,int k){
	int s=0;
	int son=0;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa) continue ;
		int tmp=dfs(v,u,k);
		++tmp;
		if(tmp==k) continue ;
		s+=tmp;
		++son;
	}
	if(s%k) --son;
	if(son!=(s/k)*2) is=false;
	return s%k;
}
int main(){
	int n;io>>n;
	for(int i=1;i<n;++i){
		int u,v;io>>u>>v;
		add(u,v);add(v,u);
	}
	for(int i=1;i<n;++i){
		if((n-1)%i) { putchar('0');continue ; }
		is=true;dfs(1,0,i);
		if(is) putchar('1');
		else putchar('0');
	}
	return 0;
}

错误之处是显然的。

Hack 数据:

15
1 2
1 3
1 4
1 5
2 6
3 7
4 8
6 9
7 10
10 12
12 14
8 11
11 13
13 15

答案应为 11000000000000

错解输出 11000010000000

2022/12/11 19:10
加载中...