QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#148782#6745. Delete the TreeSceneWA 1ms3436kbC++142.5kb2023-08-23 18:53:202023-08-23 20:28:40

Judging History

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

  • [2023-08-23 20:28:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3436kb
  • [2023-08-23 18:53:20]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define Ts template<typename Ty,typename... Ar>
#define Tp template<typename Ty>
#define ll long long
#define RS register
#define gc getchar
#define pc putchar
#define I inline
using namespace std;
Tp I Ty wmax(Ty a,Ty b){return a>=b? a:b;}
Tp I Ty wmin(Ty a,Ty b){return a<=b? a:b;}
namespace WrongIO
{
	Tp I void read(Ty &x){x=0;Ty opt=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();if(c=='-')opt=-1,c=gc();while(isdigit(c))x=(x<<3)+(x<<1),x+=c-'0',c=gc();x*=opt;return;}
	Tp I void write(Ty x){short OI_USE[50],OI_top=0;if(x<=0) if(x==0)pc('0');else pc('-'),x*=-1;while(x)OI_USE[++OI_top]=x%10,x/=10;while(OI_top--)pc(OI_USE[OI_top+1]+'0');return;}
    I void writec(char c[]){int len=strlen(c);for(int i=0;i<len;i++)pc(c[i]);}
    I void writes(string s){int len=s.length();for(int i=0;i<len;i++)pc(s[i]);}
    I void readc(char &c,int l,int r){c=gc(); while(c!=EOF&&(c<l||c>r)) c=gc();}
    I void readc(char &c,char val){c=gc();while(c!=EOF&&c!=val) c=gc();}
    I void readc(char val){char c;c=gc();while(c!=EOF&&c!=val) c=gc();}
    I void readls(string &s){char c=gc();while(c!='\n') s.push_back(c),c=gc();}
    Ts I void read(Ty &x,Ar &...y) {read(x),read(y...);}
} using namespace WrongIO;
int n;
vector<int> vt[505];
int fa[505],tp[505],cdl[505];
int ex[505],Root;
int md[505],ct=0;
int ans[15][505],act=0;
void dfs(int u,int lst)
{
	for(int v:vt[u])
	{
		if(ex[v]==0) continue;
		tp[v]++;
		if(v==lst) continue;
		fa[v]=u;
		dfs(v,u);
	}
	return;
}
void del(int u,int lst)
{
	if((tp[u]==1||tp[u]==0)&&cdl[fa[u]]==0)
	{
		cdl[u]=1,md[++ct]=u;
		ex[u]=0; n--;
	}
	if(tp[u]==2&&cdl[fa[u]]==0)
	{
		cdl[u]=1,md[++ct]=u;
		ex[u]=0;n--;int v;
		for(int z:vt[u])
		if(z!=fa[u]&&ex[z]==1) v=z;
		vt[v].push_back(fa[u]);
		vt[fa[u]].push_back(v);
	}
	for(int i=0;i<vt[u].size();i++)
	{
		int v=vt[u][i];
		if(ex[v]==0||v==lst) continue;
		del(v,u);
	}
	return;
}
int main()
{
	read(n); for(int i=1;i<=n;i++) ex[i]=1;
	for(int i=1;i<n;i++)
	{
		int a,b; read(a,b);
		vt[a].push_back(b);
		vt[b].push_back(a);
	}
	int num=n;
	while(n>=1)
	{
		memset(tp,0,sizeof(tp));
		memset(cdl,0,sizeof(cdl));
		for(int i=1;i<=num;i++) if(ex[i]) Root=i;
		dfs(Root,-1); fa[Root]=Root;
		ct=0;  del(Root,-1);
		act++;
		for(int i=1;i<=ct;i++) ans[act][i]=md[i];
		ans[act][0]=ct;
	}
	write(act+1),pc('\n');
	for(int i=1;i<=act;i++)
	{
		write(ans[i][0]),pc(' ');
		for(int j=1;j<=ans[i][0];j++)
		write(ans[i][j]),pc(' '); pc('\n');
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3436kb

input:

5
1 2
1 3
1 4
4 5

output:

4
3 5 2 3 
1 4 
1 1 

result:

wrong output format Unexpected end of file - int32 expected