Wizard's Tour CodeForces - 860D (图,构造)
大意: 给定$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 (图,构造)的更多相关文章
- 【Codeforces858F】Wizard's Tour [构造]
Wizard's Tour Time Limit: 50 Sec Memory Limit: 512 MB Description Input Output Sample Input 4 5 1 2 ...
- Wizard's Tour
F. Wizard's Tour time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- CodeForces 860D Wizard's Tour
题意 给出一张无向图,要求找出尽量多的长度为2的不同路径(边不可以重复使用,点可以重复使用) 分析 yzy:这是原题 http://www.lydsy.com/JudgeOnline/problem. ...
- Codeforces 1082 毛毛虫图构造&最大权闭合子图
A #include<bits/stdc++.h> using namespace std; typedef long long ll; , MAXM = ; //int to[MAXM ...
- Codeforces 976 正方格蛇形走位 二维偏序包含区间 度数图构造 贪心心火牧最大dmg
A #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; int main() { i ...
- POJ 1637 Sightseeing tour (混合图欧拉路判定)
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6986 Accepted: 2901 ...
- Codeforces.578E.Walking(构造)
题目链接 \(Description\) 给定一个长为\(n\)的足迹序列(只包含\(L,R\)两种字符),你需要\(LRLRLR...\)这样交替在\(L\)和\(R\)上走(第一步可以选择\(L\ ...
- Sonya and Matrix CodeForces - 1004D (数学,构造)
http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角 ...
随机推荐
- [CSP-S模拟测试]:密码(数位DP+库默尔定理)
题目描述 为了揭穿$SERN$的阴谋,$Itaru$黑进了$SERN$的网络系统.然而,想要完全控制$SERN$,还需要知道管理员密码.$Itaru$从截获的信息中发现,$SERN$的管理员密码是两个 ...
- 统计mysql某个数据库的表数量以及表记录数
统计MySQL中某个数据库中有多少张表 SELECT count(*) TABLES, table_schema FROM information_schema.TABLES where ...
- 分布式锁与实现--基于ZooKeeper实现
引言 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提 ...
- java web过滤器防止未登录进入界面
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import ja ...
- 【译】OkHttp3 拦截器(Interceptor)
一,OkHttp 拦截器介绍(译自官方文档) 官方文档:https://github.com/square/okhttp/wiki/Interceptors 拦截器是 OkHttp 提供的对 Http ...
- js小数点相乘或相除出现多位数的问题
最近做一个支付的项目需要做个计算器,所以发现了一个问题. 比如: 0.03/0.00003=999.9999999999999 0.0003*0.3=0.000029999999999999997 0 ...
- git下载fastadmin
mac git下载后,环境配置运行会如下图 一 下载相对应系统的node.js https://nodejs.org/en/download/ 安装就是一直下一步.... 二 指令终端.cd 到对应项 ...
- win10备忘
你要允许来自未知发布者 http://www.xitonghe.com/jiaocheng/Windows10-7809.html输入法 切换繁体 ctrl+shift+F win10 输入法 htt ...
- Struts2.3+Spring3.2+Hibernate4.2框架搭建
一.环境 SSH使用的版本:struts2.3.14.spring3.2.2.hibernate4.2.0 数据库:MYSQL tomcat版本:apache-tomcat-7.0.42 二.所需要导 ...
- INavigationAware接口示例
INavigationAware接口 public interface INavigationAware { bool IsNavigationTarget(NavigationContext ...