codeforces 357B Flag Day
3548 단어 codeforces
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
overall, there must be m dances;
exactly three people must take part in each dance;
each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has n dancers, and their number can be less than 3m. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the m dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the n dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
Input
The first line contains two space-separated integers n (3 ≤ n ≤ 105) and m (1 ≤ m ≤ 105) — the number of dancers and the number of dances, correspondingly. Then m lines follow, describing the dances in the order of dancing them. The i-th line contains three distinct integers — the numbers of the dancers that take part in the i-th dance. The dancers are numbered from 1 to n. Each dancer takes part in at least one dance.
Output
Print n space-separated integers: the i-th number must represent the color of the i-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
Sample test(s)
input
7 3
1 2 3
1 4 5
4 6 7
output
1 2 3 3 2 2 1
input
9 3
3 6 9
2 5 8
1 4 7
output
1 1 1 2 2 2 3 3 3
input
5 2
4 1 5
3 1 2
output
2 3 1 1 3
#include
#include #include #include using namespace std; const int maxn=111111; int col[maxn],vis[4]; void solve(int a,int b,int c) { int i; memset(vis,0,sizeof(vis)); vis[col[a]]++; vis[col[b]]++; vis[col[c]]++; for(i=1;i<=3;i++) { if(!col[a]&&!vis[i]) { col[a]=i; vis[i]=1; } } for(i=1;i<=3;i++) { if(!col[b]&&!vis[i]) { col[b]=i; vis[i]=1; } } for(i=1;i<=3;i++) { if(!col[c]&&!vis[i]) { col[c]=i; vis[i]=1; } } } int main() { int n,m; int i; int a,b,c; scanf("%d%d",&n,&m); memset(col,0,sizeof(col)); for(i=0;i 1) cout<
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.