提交时间:2023-08-25 09:51:13
运行 ID: 100233
#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline int fr(){ int x = 0,f = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x < 0){ x = -x; putchar('-'); } if (x > 9){ fw(x / 10); } putchar(x % 10 + 48); } } using namespace Fast; int ret[35],n,sum; bool mp[35][35]; 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(){ n = fr(); getchar(); for (int i = 1;i <= n;i++){ int a = fr(); int sum = 0; 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; }