Logo
(追記) (追記ここまで)

35024번 - Games of Chess 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB111100.000%

문제

There are $n$ friends and $n$ houses in Chess City, both numbered from 1ドル$ to $n,ドル where friend $i$ lives in house $i$. The houses are connected by $m$ bidirectional roads, forming a connected network.

Chess City also has $n$ virtual chess clubs, numbered from 1ドル$ to $n$. Each friend must choose exactly one club to join. These choices do not need to be distinct, so some clubs might not have any members.

When friend $i$ hosts a chess party, it is attended by every friend who belongs to the same club as friend $i$ and lives in a house directly connected to house $i$ by a road. The party is considered successful if the total number of attendees, including friend $i,ドル is even; in this case, they can all play chess simultaneously.

Choose a club for each friend so that every friend's party is successful, or report that it is impossible.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$ (1ドル \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains two integers $n$ and $m,ドル denoting the number of houses and the number of roads (2ドル \le n \le 10^5$; $n - 1 \le m \le 2 \cdot 10^5$).

Each of the following $m$ lines contains two integers $u$ and $v,ドル describing a bidirectional road between houses $u$ and $v$ (1ドル \le u, v \le n$; $u \ne v$). No two houses are connected by more than one road. It is possible to get from any house to any other one using the roads.

It is guaranteed that the sum of $n$ over all test cases does not exceed 10ドル^5,ドル and the sum of $m$ over all test cases does not exceed 2ドル \cdot 10^5$.

출력

For each test case, print a single integer $-1$ if it is impossible to assign a chess club to each friend so that every friend's party is successful.

Otherwise, print $n$ integers $c_1, c_2, \ldots, c_n,ドル where $c_i$ is the number of the chess club that friend $i$ should join (1ドル \le c_i \le n$). If there are multiple answers, print any of them.

제한

예제 입력 1

3
2 1
1 2
3 3
1 2
2 3
3 1
8 10
1 2
1 4
1 7
5 2
5 4
5 7
5 3
2 6
2 8
6 8

예제 출력 1

1 1
-1
3 3 6 6 6 2 6 2

노트

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > ICPC 2025-2026 Northwestern Russia Regional Contest G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /