大意: 给定$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. 初识 Premiere

    本记录基于Premiere Pro CC 2015.3,编号不连贯,以视频编号为准,对应视频没有有用信息的没有记录. 1.3 基本工作界面和预设工作区 将面板独立出来:按住Ctrl拖动窗口 将关闭的面 ...

  2. oc 基本语法 类 静态变量 常量

    // // ReViewClass.h // hellowWorld // 本类是oc复习练手类 // Created by hongtao on 2018/3/26. // Copyright © ...

  3. Android Butterknife(黄油刀) 使用方法总结

    前言: ButterKnife是一个专注于Android系统的View注入框架,以前总是要写很多findViewById来找到View对象,有了ButterKnife可以很轻松的省去这些步骤.是大神J ...

  4. LC 712. Minimum ASCII Delete Sum for Two Strings

    Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. ...

  5. 八十九:redis之python操作redis

    安装:pip install redis 连接 字符串操作 插入值 获取 删除值 列表操作,更多操作见源码 添加 获取 集合操作,更多操作见源码 哈希操作,更多操作见源码 事务操作:cache.pip ...

  6. iOS证书详解--转载

    一.成员介绍1.    Certification(证书)证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:1)    Developer Certification(开发证书)安装在电脑上 ...

  7. java.lang.ClassNotFoundException: org.apache.commons.dbutils.QueryRunner

    七月 28, 2017 11:06:33 下午 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() fo ...

  8. CnPack 开源软件项目

    Cnpack公共窗体库 ------------------------------ CnPack 2009-09-14 SVN 包,包括以下内容: 1. CnPack 组件包所有源代码.2. CnP ...

  9. Swift基础知识点的学习

    每一个程序员都有一颗不满足当下知识的学习,学习Swift更是每一个iOS程序员必学技能!!! 一说道基础点的学习,当然涵盖的方面也是很多很多啦....然而每一个小知识点的学习,写一个博客,我也觉得没什 ...

  10. 内网gitlab访问外网

     外网要访问内网,内网出口必须有公网ip,且外网访问内部网络可以用花生壳,可以用主机端口映射  写ansible调api,打通内网到阿里云的master节点   如何将公司内网与云服务器内网打通 参照 ...