提交时间:2023-10-22 13:50:45

运行 ID: 107374

#include<iostream> #include<cstring> #include<string> #include<cstdio> using namespace std; int n,a[30][30],cl[30]= {0}; bool vsd[30]; string s; int kd(int &x) { if(s[x]==' ') { x++; } int ru=0; while((s[x]<='9')&&(s[x]>='0')) { ru*=10; ru+=s[x++]-'0'; } return ru; } void DFS(int x) { vsd[x]=1; bool tp[5]={0}; bool compare = false; for(int i=1; i<=n; i++) { if((vsd[i])&&(a[x][i]==1)) { tp[cl[i]]=1; if(not compare) tp[cl[x-i]] = tp[cl[i-1]+1]-1 ; } } for(int i=1; i<=4; i++) { if(!tp[i]) { cl[x]=i; cout<<cl[x]<<" "; return; } } return; } int main() { //freopen("map.in","r",stdin); //freopen("map.out","w",stdout); cin>>n; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { a[i][j]=-1; } } getline(cin,s); for(int i=1; i<=n; i++) { getline(cin,s); int j=0; kd(j); while(j<s.length()) { int q=kd(j); a[i][q]=1; a[q][i]=1; j++; } } for(int i=1; i<=n; i++) { DFS(i); } cout<<endl; return 0; }