CF1610F.Mashtali: a Space Oddysey

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Lee was planning to get closer to Mashtali's heart to proceed with his evil plan(which we're not aware of, yet), so he decided to beautify Mashtali's graph. But he made several rules for himself. And also he was too busy with his plans that he didn't have time for such minor tasks, so he asked you for help.

Mashtali's graph is an undirected weighted graph with nn vertices and mm edges with weights equal to either 11 or 22. Lee wants to direct the edges of Mashtali's graph so that it will be as beautiful as possible.

Lee thinks that the beauty of a directed weighted graph is equal to the number of its Oddysey vertices. A vertex vv is an Oddysey vertex if ∣d+(v)−d−(v)∣=1|d^+(v) - d^-(v)| = 1, where d+(v)d^+(v) is the sum of weights of the outgoing from vv edges, and d−(v)d^-(v) is the sum of the weights of the incoming to vv edges.

Find the largest possible beauty of a graph that Lee can achieve by directing the edges of Mashtali's graph. In addition, find any way to achieve it.

Note that you have to orient each edge.

Lee 为了推进其邪恶计划(我们目前尚不清楚具体内容),打算拉近与 Mashtali 的关系,因此决定美化 Mashtali 的图。但他为自己设定了若干规则。此外,由于他正忙于筹划,无暇顾及此类琐事,于是请求你帮忙。

Mashtali 的图是一个含 nn 个顶点、mm 条边的无向带权图,每条边的权重为 11 或 22。Lee 希望将 Mashtali 图中的每条边定向,使其尽可能“美丽”。

Lee 认为一个有向带权图的“美丽值”等于其 Oddysey 顶点 的数量。顶点 vv 被称为 Oddysey 顶点,当且仅当 ∣d+(v)−d−(v)∣=1|d^+(v) - d^-(v)| = 1,其中 d+(v)d^+(v) 表示从 vv 出发的所有出边的权重之和,d−(v)d^-(v) 表示所有指向 vv 的入边的权重之和。

请找出 Lee 通过对 Mashtali 图的边进行定向所能达到的最大美丽值,并给出一种达到该最大值的具体定向方案。

注意:你必须对每条边都指定方向。

输入格式

The first line contains two integers nn and mm (1≤n≤105;  1≤m≤105)(1 \le n \le 10^5;\; 1 \le m \le 10^5) — the numbers of vertices and edges in the graph.

The ii-th line of the following mm lines contains three integers uiu_i, viv_i and wiw_i (1≤ui,vi≤n;  ui≠vi;  wi∈1,2)( 1 \le u_i , v_i \le n;\; u_i \neq v_i;\; \bf{w_i \in {1, 2}} ) — the endpoints of the ii-th edge and its weight.

Note that the graph doesn't have to be connected, and it might contain multiple edges.

第一行包含两个整数 nn 和 mm (1≤n≤105;  1≤m≤105)(1 \le n \le 10^5;\; 1 \le m \le 10^5) —— 分别表示图中顶点和边的数量。

接下来的 mm 行中,第 ii 行包含三个整数 uiu_i、viv_i 和 wiw_i (1≤ui,vi≤n;  ui≠vi;  wi∈1,2)( 1 \le u_i , v_i \le n;\; u_i \neq v_i;\; \bf{w_i \in {1, 2}} ) —— 分别表示第 ii 条边的两个端点及其权重。

注意:该图未必连通,且可能包含重边。

输出格式

In the first line print a single integer — the maximum beauty of the graph Lee can achieve.

In the second line print a string of length mm consisting of 11s and 22s — directions of the edges.

If you decide to direct the ii-th edge from vertex uiu_i to vertex viv_i, ii-th character of the string should be 11. Otherwise, it should be 22.

第一行输出一个整数——Lee 能达到的最大图的美观度。

第二行输出一个长度为 mm 的字符串,仅由字符 11 和 22 组成——表示各条边的方向。

若你决定将第 ii 条边从顶点 uiu_i 指向顶点 viv_i,则该字符串的第 ii 个字符应为 11;否则应为 22。

输入输出样例

  • 输入#1

    6 7
    1 2 1
    1 3 2
    2 3 2
    1 4 1
    4 5 1
    2 5 2
    2 6 2

    输出#1

    2
    1212212
  • 输入#2

    6 7
    1 2 2
    1 3 2
    2 3 2
    1 4 2
    4 5 2
    2 5 2
    2 6 2

    输出#2

    0
    1212212
  • 输入#3

    6 7
    1 2 1
    1 3 1
    2 3 1
    1 4 1
    4 5 1
    2 5 1
    2 6 1

    输出#3

    2
    1212212

说明/提示

Explanation for the first sample:

vertices 22 and 55 are Oddyseys.

Explanation for the third sample:

vertices 11 and 66 are Oddyseys.

第一个样例的解释:

顶点 22 和 55 是奥德赛点(Oddyseys)。

第三个样例的解释:

顶点 11 和 66 是奥德赛点(Oddyseys)。

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

首页