#P13370. [GCJ 2011 #1B] House of Kittens

    ID: 15237 远端评测题 6000~12000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2011Special Judge平面图Google Code Jam

[GCJ 2011 #1B] House of Kittens

题目描述

You have recently adopted some kittens, and now you want to make a house for them. On the outside, the house will be shaped like a convex polygon with NN vertices. On the inside, it will be divided into several rooms by MM interior walls connecting vertices along straight lines. No two walls will ever cross, but there might be multiple walls touching a single vertex.

So why is your house of kittens going to be so special? At every vertex, you are going to build a pillar entirely out of catnip! Kittens will be able to play with any pillar that touches the room they are in, giving them a true luxury home.

To make the house even more exciting, you want to use different flavors of catnip. A single pillar can only use one flavor, but different pillars can use different flavors. There is only one problem. If some room does not have access to all the catnip flavors in the house, then the kittens in that room will feel left out and be sad.

Your task is to choose what flavor of catnip to use for each vertex in such a way that (a) every flavor is accessible from every room, and (b) as many flavors as possible are used.

In the following example, three different flavors (represented by red, green, and blue dots) are distributed across an 8-sided house while keeping the kittens in every room happy:

In the image above, starting at the left corner of the top wall and going clockwise, the colors here are: green, blue, red, red, blue, green, blue, red.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case consists of three lines. The first line gives NN and MM, the number of vertices and interior walls in your cat house. The second lines gives space-separated integers U1U_1, U2U_2, ..., UMU_M describing where each interior wall begins. The third lines gives space-separated integers V1V_1, V2V_2, ..., VMV_M describing where each interior wall ends.

More precisely, if the vertices of your cat house are labeled 11, 22, ..., NN in clockwise order, then the interior walls are between vertices U1U_1 and V1V_1, U2U_2 and V2V_2, etc.

输出格式

For each test case, output two lines. The first should be "Case #xx: CC", where xx is the case number, and CC is the maximum number of catnip flavors that can be used. The second line should contain NN space-separated integers: "y1y_1 y2y_2 ... yNy_N", where yiy_i is an integer between 11 and CC indicating which catnip flavor you assigned to vertex ii.

If there are multiple assignments with CC flavors, you may output any of them.

2
4 1
2
4
8 3
1 1 4
3 7 7
Case #1: 3
1 2 1 3
Case #2: 3
1 2 3 1 1 3 2 3

提示

Limits

  • 1T1001 \leq T \leq 100.
  • 1MN31 \leq M \leq N - 3.
  • 1Ui<ViN1 \leq U_i < V_i \leq N for all ii.
  • Interior walls do not touch each other except at the NN vertices.
  • Interior walls do not touch the outside of the house except at the NN vertices.

Small dataset (20 Pts, Test set 1 - Visible)

  • 4N84 \leq N \leq 8.
  • Time limit: 30 6 seconds.

Large dataset (25 Pts, Test set 2 - Hidden)

  • 4N20004 \leq N \leq 2000.
  • Time limit: 60 12 seconds.