cf B. Flag Day
http://codeforces.com/contest/357/problem/B
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 100010 5 using namespace std; 6 7 int g[maxn][4]; 8 int n,m; 9 int vis[maxn]; 10 int num[maxn]; 11 bool vis1[4]; 12 13 14 15 int main() 16 { 17 while(scanf("%d%d",&n,&m)!=EOF) 18 { 19 memset(vis,0,sizeof(vis)); 20 for(int i=1; i<=m; i++) 21 { 22 int x,y,z; 23 scanf("%d%d%d",&x,&y,&z); 24 if(num[x]) 25 { 26 num[y]=num[x]%3+1; 27 num[z]=num[y]%3+1; 28 } 29 else if(num[y]) 30 { 31 num[z]=num[y]%3+1; 32 num[x]=num[z]%3+1; 33 } 34 else if(num[z]) 35 { 36 num[x]=num[z]%3+1; 37 num[y]=num[x]%3+1; 38 } 39 else 40 { 41 num[x]=1; 42 num[y]=2; 43 num[z]=3; 44 } 45 } 46 for(int i=1; i<=n; i++) 47 { 48 if(i==1) 49 printf("%d",num[i]); 50 else printf(" %d",num[i]); 51 } 52 printf("\n"); 53 } 54 return 0; 55 }