[杂题]Codeforces 860D. Wizard's Tour
来源:互联网 发布:管家婆软件售后电话 编辑:程序博客网 时间:2024/05/16 05:22
Solution
首先答案的上界是
考虑
一个点如果连向子树的点的边有偶数条,那么把这些点一对一的加到答案里面。
如果只有奇数条,那么就要考虑把连向父节点的边也加进来。
在
这样就得到的答案为
学到了
这个(哪次忘了呀。。)
#include <bits/stdc++.h>using namespace std;const int N = 202020;const int INF = 1 << 30;typedef long long ll;typedef tuple<int, int, int> Tuples;inline char get(void) { static char buf[100000], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, 100000, stdin); if (S == T) return EOF; } return *S++;}template<typename T>inline void read(T &x) { static char c; x = 0; int sgn = 0; for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1; for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0'; if (sgn) x = -x;}int n, m, x, y, z, clc;vector<int> G[N];int deg[N], pre[N];vector<Tuples> ans;inline void AddEdge(int from, int to) { G[from].push_back(to); G[to].push_back(from);}inline int dfs(int u, int fa) { pre[u] = ++clc; int lst, ned, d = 0; for (int to: G[u]) { if (to == fa) continue; if (!pre[to]) ned = dfs(to, u); else ned = (pre[to] > pre[u]); if (!ned) continue; if (d) ans.push_back(Tuples(lst, u, to)); d ^= 1; lst = to; } if (d && fa) { ans.push_back(Tuples(fa, u, lst)); return 0; } return 1;}int main(void) { freopen("1.in", "r", stdin); read(n); read(m); for (int i = 1; i <= m; i++) { read(x); read(y); AddEdge(x, y); ++deg[x]; ++deg[y]; } for (int i = 1; i <= n; i++) if (!pre[i]) dfs(i, 0); printf("%d\n", ans.size()); for (int i = 0; i < ans.size(); i++) { tie(x, y, z) = ans[i]; printf("%d %d %d\n", x, y, z); } return 0;}
阅读全文
2 0
- [杂题]Codeforces 860D. Wizard's Tour
- codeforces 858F Wizard's Tour
- CodeforceF. Wizard's Tour
- 【Codeforces858F】Wizard's Tour
- Codeforces 858F ( Codeforces Round #434 Div. 2 F ) Wizard's Tour 图论dfs
- CF 858F Wizard's Tour (DFS)
- Codeforces 66D World tour BFS+枚举
- Codeforces 667D World Tour (最短路+枚举)
- Codeforces 667D World Tour【最短路+枚举】
- Codeforces Round #349 (Div. 2) D. World Tour
- Codeforces 667D World Tour【最短路+思维】好题!
- CodeForces 216D Spider's Web
- Codeforces 30D King's Problem? 模拟
- 【CODEFORCES】 D. Pashmak and Parmida's problem
- CodeForces 118D Caesar's Legions
- codeforces 505 D Mr. Kitayuta's Technology
- Codeforces 542 D. Superhero's Job
- Codeforces 118D Caesar's Legions
- CSS3&HTML5各浏览器支持情况一览表
- 最详细的Vuex教程
- Centos7 zookeeper-3.4.8集群搭建
- Beyond Compare对比相同文件为什么显示红色
- SVN解除项目版本控制
- [杂题]Codeforces 860D. Wizard's Tour
- Sublime Text 3 、WebStorm配置实时刷新
- css的配置文件reset的总结
- Hash表
- 数组拷贝的方法比较
- Android VideoView 自定义播放器 MediaController 实现视频播放控制和横竖屏适配
- [LR]web接口性能脚本的处理点小结
- Java编程示例
- 从pymongo 提取最近100条数据