CF1228D.Complete Tripartite

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a simple undirected graph consisting of nn vertices and mm edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.

Let's make a definition.

Let v1v_1 and v2v_2 be two some nonempty subsets of vertices that do not intersect. Let f(v1,v2)f(v_{1}, v_{2}) be true if and only if all the conditions are satisfied:

  1. There are no edges with both endpoints in vertex set v1v_1.
  2. There are no edges with both endpoints in vertex set v2v_2.
  3. For every two vertices xx and yy such that xx is in v1v_1 and yy is in v2v_2, there is an edge between xx and yy.

Create three vertex sets (v1v_{1}, v2v_{2}, v3v_{3}) which satisfy the conditions below;

  1. All vertex sets should not be empty.
  2. Each vertex should be assigned to only one vertex set.
  3. f(v1,v2)f(v_{1}, v_{2}), f(v2,v3)f(v_{2}, v_{3}), f(v3,v1)f(v_{3}, v_{1}) are all true.

Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.

你有一个由 nn 个顶点和 mm 条边构成的简单无向图。该图不含自环,且任意两个顶点之间至多存在一条边。给定的图可以是非连通的。

我们给出如下定义:

设 v1v_1 和 v2v_2 是两个非空且互不相交的顶点子集。当且仅当满足以下全部条件时,f(v1,v2)f(v_{1}, v_{2}) 为真:

  1. 顶点集 v1v_1 中任意两个顶点之间均无边相连;
  2. 顶点集 v2v_2 中任意两个顶点之间均无边相连;
  3. 对任意两个顶点 xx 和 yy,若 x∈v1x \in v_1 且 y∈v2y \in v_2,则 xx 与 yy 之间必有一条边。

请构造三个顶点集(v1v_{1}、v2v_{2}、v3v_{3}),使其满足以下条件:

  1. 所有顶点集均非空;
  2. 每个顶点恰好属于且仅属于其中一个顶点集;
  3. f(v1,v2)f(v_{1}, v_{2})、f(v2,v3)f(v_{2}, v_{3})、f(v3,v1)f(v_{3}, v_{1}) 均为真。

是否存在满足上述条件的三个顶点集?若存在,请输出每个顶点所属的顶点集编号(即对每个顶点输出其属于 v1v_1、v2v_2 还是 v3v_3)。

输入格式

The first line contains two integers nn and mm (3≤n≤1053 \le n \le 10^{5}, 0≤m≤min(3⋅105,n(n−1)2)0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})) — the number of vertices and edges in the graph.

The ii-th of the next mm lines contains two integers aia_{i} and bib_{i} (1≤ai<bi≤n1 \le a_{i} \lt b_{i} \le n) — it means there is an edge between aia_{i} and bib_{i}. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.

第一行包含两个整数 nn 和 mm(3≤n≤1053 \le n \le 10^{5},0≤m≤min(3⋅105,n(n−1)2)0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})),分别表示图中的顶点数和边数。

接下来的 mm 行中,第 ii 行包含两个整数 aia_{i} 和 bib_{i}(1≤ai<bi≤n1 \le a_{i} \lt b_{i} \le n),表示顶点 aia_{i} 与 bib_{i} 之间存在一条边。图中不含自环,任意一对顶点之间至多只有一条边。给定的图可能不连通。

输出格式

If the answer exists, print nn integers. ii-th integer means the vertex set number (from 11 to 33) of ii-th vertex. Otherwise, print −1-1.

If there are multiple answers, print any.

如果答案存在,输出 nn 个整数;其中第 ii 个整数表示第 ii 个顶点所属的顶点集编号(编号范围为 11 到 33)。否则,输出 −1-1。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    6 11
    1 2
    1 3
    1 4
    1 5
    1 6
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6

    输出#1

    1 2 2 3 3 3
  • 输入#2

    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4

    输出#2

    -1

说明/提示

In the first example, if v1=1v_{1} = { 1 }, v2=2,3v_{2} = { 2, 3 }, and v3=4,5,6v_{3} = { 4, 5, 6 } then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well.

In the second example, it's impossible to make such vertex sets.

在第一个例子中,若 v1=1v_{1} = { 1 }、v2=2,3v_{2} = { 2, 3 }、v3=4,5,6v_{3} = { 4, 5, 6 },则顶点集将满足所有条件。但你也可以以其他方式将顶点分配至顶点集;例如,“2 3 3 1 1 1”等答案同样可被接受。

在第二个例子中,无法构造出满足要求的顶点集。

输入解题思路,AI测评打分。不知道怎么写?

首页