#P14501. [NCPC 2025] Gotta Trade Some of 'Em

    ID: 14436 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>并查集2025Special Judge连通块ICPC

[NCPC 2025] Gotta Trade Some of 'Em

题目背景

:::align{center}

Two Game Boy systems connected with a DMG-04 (link cable). Public domain photo by KoS.

:::

题目描述

The kids at school are obsessed with a new video game of collectible pocket monsters called Pokeˊmon\emph{Pokémon}. Their goal is to "catch 'em all" by completing the Pokédex, meaning they want to catch a copy of every Pokémon. Typically they do this by playing the game, encountering Pokémon, and catching them with a Pokéball.

Pokémon games are released in different variants. Each variant contains a number of Pokémon, some of which are exclusive to that variant. For example, only Pokeˊmon Blue\emph{Pokémon Blue} (variant 11) allows encounters with the Pokémon known as Meowth. Thus, a kid owning Pokeˊmon Red\emph{Pokémon Red} (variant 22) cannot catch Meowth, and therefore must trade with a friend who has a Meowth to fill the Pokédex. This friend may either own Pokémon Blue or have received Meowth through another trade.

Your task is to distribute Pokémon variants to the kids so that, through trading among friends, every kid can eventually collect at least one of each Pokémon. Each kid receives exactly one Pokémon game variant. Each variant comes with enough copies of its Pokémon, both its exclusives and the non-exclusives, ensuring trades are always possible.

输入格式

The input consists of:

  • One line with three integers nn, mm, and kk: the number nn of kids, with 1n1000001 \leq n \leq 100\,000, the number mm of friendships, with 1m2000001 \leq m \leq 200\,000, and the number kk of different game variants, with 1k1000001 \leq k \leq 100\,000.
  • mm lines, each containing two integers aa and bb with 1a<bn1\leq a < b \leq n, representing that aa and bb are friends.

输出格式

Output nn integers, one for each kid, representing which game variant that kid should get. Your output will be considered correct if all kids can fill their Pokédex by using any number of trades with their friends.

If there are multiple valid solutions, you may output any one of them.

If there is no assignment of game variants to kids that allows all kids to fill their Pokédex, output impossible\texttt{impossible}.

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