求助,WA on #4
查看原帖
求助,WA on #4
724676
Iwara_qwq楼主2022/8/29 15:28
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
using namespace std;
namespace Yorihime_Nao{
	template<class T> T MAX(T x,T y){
		return x>y?x:y;
	}
	template<class T> T MIN(T x,T y){
		return x<y?x:y;
	}
	template<class T,class ... Arg> T MAX(T x,T y,Arg ... arg){
		return MAX(x>y?x:y,arg...);
	}
	template<class T,class ... Arg> T MIN(T x,T y,Arg ... arg){
		return MIN(x<y?x:y,arg...);
	}
	template<class T> T lowbit(T x){
		return x&-x;
	}
	template<class T> void SWAP(T &x,T &y){
		T qwq;
		qwq=x;
		x=y;
		y=qwq;
		return;
	}
}
using namespace Yorihime_Nao;
ll T;
ll n;
struct node{
	ll l;
	ll a[205];
};
node t[205];
ll ans[205];
ll reg[205],pos[205];
bool vis[205],check_arr[205];
bool check(ll delta){
//	cout<<"check:"<<endl;
//	cout<<delta<<" ";
	ans[1]=delta;
	pos[delta]=1;
	for(int i=1;i<=n;i++)vis[i]=0;
	vis[delta]=1;
	for(int i=1;i<n;i++){
		reg[i]=t[i].l;
		for(int j=1;j<=t[i].l;j++)if(t[i].a[j]==delta){
			reg[i]--;
			break;
		}
	}
	for(int i=2;i<=n;i++){
		ll tmp=-1,qwq=0,id=-1;
		for(int j=1;j<n;j++){
			if(reg[j]!=1)continue;
			for(int k=1;k<=t[j].l;k++)if(!vis[t[j].a[k]])tmp=t[j].a[k],qwq++,id=j;
		}
		if(qwq!=1){
//			cout<<endl;
			return 0;
		}
		ans[i]=tmp;
		pos[tmp]=i;
		vis[tmp]=1;
//		cout<<tmp<<" ";
		for(int j=1;j<n;j++)for(int k=1;k<=t[j].l;k++)if(t[j].a[k]==tmp)reg[j]--;
	}
//	cout<<endl;
	for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++)check_arr[j]=0;
		for(int j=1;j<=t[i].l;j++)check_arr[pos[t[i].a[j]]]=1;
		for(int j=1;j<=n;j++)if(check_arr[j]==1&&!check_arr[j-1]&&!check_arr[j+1]){
//			cout<<"^"<<endl;
			return 0;
		}
	}
	return 1;
}
int main(){
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1;i<=n-1;i++){
			cin>>t[i].l;
			for(int j=1;j<=t[i].l;j++)cin>>t[i].a[j];
		}
		for(int i=1;i<=n;i++)if(check(i)){
//			cout<<"qwq"<<endl;
			break;
		}
		for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
		cout<<endl;
	}
	return 0;
}

2022/8/29 15:28
加载中...