CF858F.Wizard's Tour

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!

It is well-known that there are n cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that the road network is connected, i.e. it is possible that you can't reach some city from some other.

The tour will contain several episodes. In each of the episodes:

  • the wizard will disembark at some city x from the Helicopter;
  • he will give a performance and show a movie for free at the city x;
  • he will drive to some neighboring city y using a road;
  • he will give a performance and show a movie for free at the city y;
  • he will drive to some neighboring to y city z;
  • he will give a performance and show a movie for free at the city z;
  • he will embark the Helicopter and fly away from the city z.

It is known that the wizard doesn't like to use roads, so he agrees to use each road at most once (regardless of direction). In other words, for road between a and b he only can drive once from a to b, or drive once from b to a, or do not use this road at all.

The wizards wants to plan as many episodes as possible without violation the above rules. Help the wizard!

Please note that the wizard can visit the same city multiple times, the restriction is on roads only.

所有贝尔兰居民都在翘首期盼巫师驾驶他的蓝色直升机,前所未有地飞越贝尔兰各城市的巡演!

众所周知,贝尔兰共有 nn 座城市,其中某些城市对之间由双向道路连接。任意两座城市之间至多只有一条道路相连。道路网络未必连通,即可能存在从某座城市无法到达另一座城市的情况。

此次巡演将包含若干场次(episodes)。在每一场次中:

  • 巫师将从直升机上在某座城市 xx 下机;
  • 他将在城市 xx 进行表演并免费放映电影;
  • 他将沿一条道路驱车前往某个与 xx 相邻的城市 yy;
  • 他将在城市 yy 进行表演并免费放映电影;
  • 他将沿一条道路驱车前往某个与 yy 相邻的城市 zz;
  • 他将在城市 zz 进行表演并免费放映电影;
  • 他将登上直升机,从城市 zz 离开。

已知巫师不喜欢使用道路,因此他同意每条道路至多使用一次(不区分方向)。换言之,对于连接城市 aa 和 bb 的道路,他仅可从 aa 驾车至 bb 一次,或从 bb 驾车至 aa 一次,或完全不使用该道路。

巫师希望在不违反上述规则的前提下,规划尽可能多的场次。请帮助巫师!

请注意:巫师可以多次访问同一座城市,限制仅针对道路的使用次数。

输入格式

The first line contains two integers n, m (1 ≤ n ≤ 2·105, 0 ≤ m ≤ 2·105) — the number of cities and the number of roads in Berland, respectively.

The roads description follow, one in each line. Each description is a pair of two integers a__i, b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i), where a__i and b__i are the ids of the cities connected by the i-th road. It is guaranteed that there are no two roads connecting the same pair of cities. Every road is bidirectional. The cities are numbered from 1 to n.

It is possible that the road network in Berland is not connected.

第一行包含两个整数 nn、mm(1 ≤ n ≤ 2⋅1051 ≤ n ≤ 2·10^5,0 ≤ m ≤ 2⋅1050 ≤ m ≤ 2·10^5),分别表示 Berland 的城市数量和道路数量。

接下来 mm 行,每行描述一条道路。每条道路由一对整数 ai, bia_i,\,b_i(1 ≤ ai, bi ≤ n1 ≤ a_i,\,b_i ≤ n,且 ai ≠ bia_i ≠ b_i)组成,表示第 ii 条道路连接的城市编号分别为 aia_i 和 bib_i。保证不存在两条道路连接同一对城市。所有道路均为双向道路。城市编号从 11 到 nn。

Berland 的道路网络可能不连通。

输出格式

In the first line print w — the maximum possible number of episodes. The next w lines should contain the episodes in format x, y, z — the three integers denoting the ids of the cities in the order of the wizard's visits.

第一行输出 w —— 最多可能的集数。接下来的 w 行应按格式 x, y, z 输出各集,其中三个整数表示巫师访问城市的顺序编号。

输入输出样例

  • 输入#1

    4 5
    1 2
    3 2
    2 4
    3 4
    4 1

    输出#1

    2
    1 4 2
    4 3 2
  • 输入#2

    5 8
    5 3
    1 2
    4 5
    5 1
    2 5
    4 3
    1 4
    3 2

    输出#2

    4
    1 4 5
    2 3 4
    1 5 3
    5 2 1

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

首页