CF1228D.Complete Tripartite
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a simple undirected graph consisting of n vertices and m 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 v1 and v2 be two some nonempty subsets of vertices that do not intersect. Let f(v1,v2) be true if and only if all the conditions are satisfied:
- There are no edges with both endpoints in vertex set v1.
- There are no edges with both endpoints in vertex set v2.
- For every two vertices x and y such that x is in v1 and y is in v2, there is an edge between x and y.
Create three vertex sets (v1, v2, v3) which satisfy the conditions below;
- All vertex sets should not be empty.
- Each vertex should be assigned to only one vertex set.
- f(v1,v2), f(v2,v3), f(v3,v1) are all true.
Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.
你有一个由 n 个顶点和 m 条边构成的简单无向图。该图不含自环,且任意两个顶点之间至多存在一条边。给定的图可以是非连通的。
我们给出如下定义:
设 v1 和 v2 是两个非空且互不相交的顶点子集。当且仅当满足以下全部条件时,f(v1,v2) 为真:
- 顶点集 v1 中任意两个顶点之间均无边相连;
- 顶点集 v2 中任意两个顶点之间均无边相连;
- 对任意两个顶点 x 和 y,若 x∈v1 且 y∈v2,则 x 与 y 之间必有一条边。
请构造三个顶点集(v1、v2、v3),使其满足以下条件:
- 所有顶点集均非空;
- 每个顶点恰好属于且仅属于其中一个顶点集;
- f(v1,v2)、f(v2,v3)、f(v3,v1) 均为真。
是否存在满足上述条件的三个顶点集?若存在,请输出每个顶点所属的顶点集编号(即对每个顶点输出其属于 v1、v2 还是 v3)。
输入格式
The first line contains two integers n and m (3≤n≤105, 0≤m≤min(3⋅105,2n(n−1))) — the number of vertices and edges in the graph.
The i-th of the next m lines contains two integers ai and bi (1≤ai<bi≤n) — it means there is an edge between ai and bi. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
第一行包含两个整数 n 和 m(3≤n≤105,0≤m≤min(3⋅105,2n(n−1))),分别表示图中的顶点数和边数。
接下来的 m 行中,第 i 行包含两个整数 ai 和 bi(1≤ai<bi≤n),表示顶点 ai 与 bi 之间存在一条边。图中不含自环,任意一对顶点之间至多只有一条边。给定的图可能不连通。
输出格式
If the answer exists, print n integers. i-th integer means the vertex set number (from 1 to 3) of i-th vertex. Otherwise, print −1.
If there are multiple answers, print any.
如果答案存在,输出 n 个整数;其中第 i 个整数表示第 i 个顶点所属的顶点集编号(编号范围为 1 到 3)。否则,输出 −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=1, v2=2,3, and v3=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=1、v2=2,3、v3=4,5,6,则顶点集将满足所有条件。但你也可以以其他方式将顶点分配至顶点集;例如,“2 3 3 1 1 1”等答案同样可被接受。

在第二个例子中,无法构造出满足要求的顶点集。
输入解题思路,AI测评打分。不知道怎么写?