大意: 给定$n$节点$m$条边无向图, 不保证连通, 求选出最多邻接边, 每条边最多选一次.

上界为$\lfloor\frac{m}{2}\rfloor$, $dfs$贪心划分显然可以达到上界.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m, cnt, vis[N];
vector<int> g[N];
struct {int x,y,z;} f[N];
void add(int x, int y, int z) {
f[++cnt]={x,y,z};
}
int dfs(int x) {
vis[x] = ++*vis;
int lst = 0;
for (int y:g[x]) {
if (!vis[y]) {
int t = dfs(y);
if (t) add(x,y,t);
else if (lst) add(lst,x,y),lst=0;
else lst = y;
}
else if (vis[y]>vis[x]) {
if (lst) add(lst,x,y),lst=0;
else lst = y;
}
}
return lst;
}
int main() {
scanf("%d%d", &n, &m);
REP(i,1,m) {
int u=rd(),v=rd();
g[u].pb(v),g[v].pb(u);
}
REP(i,1,n) if (!vis[i]) dfs(i);
printf("%d\n",cnt);
REP(i,1,cnt) printf("%d %d %d\n",f[i].x,f[i].y,f[i].z);
}

Wizard's Tour CodeForces - 860D (图,构造)的更多相关文章

  1. 【Codeforces858F】Wizard's Tour [构造]

    Wizard's Tour Time Limit: 50 Sec  Memory Limit: 512 MB Description Input Output Sample Input 4 5 1 2 ...

  2. Wizard's Tour

    F. Wizard's Tour time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  3. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  4. CodeForces 860D Wizard's Tour

    题意 给出一张无向图,要求找出尽量多的长度为2的不同路径(边不可以重复使用,点可以重复使用) 分析 yzy:这是原题 http://www.lydsy.com/JudgeOnline/problem. ...

  5. Codeforces 1082 毛毛虫图构造&最大权闭合子图

    A #include<bits/stdc++.h> using namespace std; typedef long long ll; , MAXM = ; //int to[MAXM ...

  6. Codeforces 976 正方格蛇形走位 二维偏序包含区间 度数图构造 贪心心火牧最大dmg

    A #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; int main() { i ...

  7. POJ 1637 Sightseeing tour (混合图欧拉路判定)

    Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6986   Accepted: 2901 ...

  8. Codeforces.578E.Walking(构造)

    题目链接 \(Description\) 给定一个长为\(n\)的足迹序列(只包含\(L,R\)两种字符),你需要\(LRLRLR...\)这样交替在\(L\)和\(R\)上走(第一步可以选择\(L\ ...

  9. Sonya and Matrix CodeForces - 1004D (数学,构造)

    http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角 ...

随机推荐

  1. 设置object的key为变量

    https://blog.csdn.net/shu580231/article/details/81367271

  2. postgresql-基础-1

    概述 层状关系 网状关系 关系型数据库 关系型数据库 ​ 元祖:代表一行 ​ 属性:代表一列 ​ 主码:唯一确定一个元组的属性组,即主键 ​ 域:属性的取值范围 ​ 分量:元组中的一个属性值,即某一行 ...

  3. Nginx-rtmp点播之complex handshake

    1. 点播的配置 假设配置文件 nginx.conf 中对 rtmp 配置如下: # 创建的子进程数 worker_processes 1; #error_log logs/error.log; er ...

  4. vue——父组件向子组件传递数据

    看例子: //注册一个全局组件,组件标签名为child Vue.component('child', { props: ['msg'], //接收父组件传递的数据 template: '<h3& ...

  5. PHP中获取数组中单列的值

    PHP中获取数组中单列的值如下: 利用PHP中的数组函数 array_column():返回数组中某个单列的值.(PHP 5.5+适用) 语法: array_column(array,column_k ...

  6. When Database Sharding is Appropriate DATABASE SHARDING

    w横切 http://www.agildata.com/database-sharding/ When Database Sharding is Appropriate Database Shardi ...

  7. json-lib json反序列化——日期转换

    将json格式的字符串转为对象,其中key-value有将String的日期转为Date类型,怪现象就是,转出来的Date类型的值是当前的系统时间. 网上有许多答案,在反序列化之前需要注册Date解析 ...

  8. Throwable 源码阅读

    Throwable 属性说明 /** * Java 语言中所有错误和异常的基类,此类及其子类才能通过 throws 被 JVM 虚拟机抛出. * @since 1.0 */ public class ...

  9. 技术选型之Docker容器引擎

    https://mp.weixin.qq.com/s?__biz=Mzg3NjAyOTUzMQ==&mid=2247484524&idx=1&sn=ac041bf3e36dda ...

  10. HTML头信息标签和标题标签

    <html> <!-- 头信息的作用 1. 可以设置网页的标题. 2. 可以通知浏览使用指定的码表解释html页面. --> <head> <meta htt ...