提交时间:2023-08-25 09:57:49

运行 ID: 100238

#include<iostream> #include<cstdio> using namespace std; int ret[35],n,sum; bool mp[35][35],done; bool check(int x,int y){ for (int i = 1;i <= n;i++){ if (mp[x][i] && ret[i] == y){ return false; } } return true; } void dfs(int cur){ if (cur > n){ for (int i = 1;i <= n;i++){ cout<<ret[i]<<' '; } exit(0); } for (int i = 1;i <= 4;i++){ if (check(cur,i)){ ret[cur] = i; dfs(cur + 1); ret[cur] = 0; } } } signed main(){ cin>>n; getchar(); for (int i = 1;i <= n;i++){ int a,sum = 0; cin>>a; while (1){ char c = getchar(); if (c == '\n'){ mp[a][sum] = true; break; } if (c < '0' || c > '9'){ mp[a][sum] = true; sum = 0; } else{ sum = (sum << 1) + (sum << 3) + (c ^ 48); } } } dfs(1); return 0; }