cf 858F
来源:互联网 发布:淘宝卖家插件哪个好 编辑:程序博客网 时间:2024/05/18 17:43
题意:
在无环图上求最多的三元组,点可以重复选。
题解:
坑爹ozy不告诉我输出要按顺序,浪费我50多分钟啊啊啊啊。
于是就转载吧。ozy的博客
code:
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespace std;struct node{ int x,y,next;}b[500010],a[500010];int len=0,last[200010];struct ANS{ int x,y,z;}ans[1000010];int num=0;int Len=0,Last[200010];bool vis[200010];int n,m,f[200010];int cd[200010]; int findfa(int x){ if(f[x]!=x) f[x]=findfa(f[x]); return f[x];}void ins(int x,int y){ a[++len].x=x;a[len].y=y; a[len].next=last[x];last[x]=len;}void insert(int x,int y){ b[++Len].x=x;b[Len].y=y; b[Len].next=Last[x];Last[x]=Len;}void dfs(int x,int fa){ vis[x]=true; for(int i=last[x];i;i=a[i].next) { int y=a[i].y; if(y!=fa) dfs(y,x); } if(cd[x]%2==1) { if(fa==0) Last[x]=b[Last[x]].next; else { insert(x,fa); cd[x]++; } } else if(fa!=0) insert(fa,x),cd[fa]++; int i=Last[x]; while(i) { int X=b[i].y; i=b[i].next; int Y=b[i].y; i=b[i].next; num++; ans[num].x=X;ans[num].y=x;ans[num].z=Y; }}int main(){ scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) f[i]=i; memset(last,0,sizeof(last)); memset(Last,0,sizeof(Last)); memset(cd,0,sizeof(cd)); for(int i=1;i<=m;i++) { int x,y;scanf("%d %d",&x,&y); int tx=findfa(x),ty=findfa(y); if(tx!=ty) { f[ty]=tx; ins(x,y); ins(y,x); } else insert(x,y),cd[x]++; } memset(vis,false,sizeof(vis)); for(int i=1;i<=n;i++) if(!vis[i]) dfs(i,0); printf("%d\n",num); for(int i=1;i<=num;i++) printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);}
阅读全文
2 0
- cf 858F
- cf 76F DP
- 【CF 526F】【奇袭】
- 【CF 534F】Game
- CF 725F 贪心
- CF 240F TorCoder
- CF 780F(copy)
- 【转】cf 825F
- CF 858F Wizard's Tour (DFS)
- CF 581F 树形dp
- Cf 120 F 【vector+dfs】
- CF 632F Magic Matrix
- CF 589F 贪心+二分
- CF 271F,区间gcd
- [CF 732F]Tourist Reform
- CF 240F TorCoder(线段树)
- CF 379F: New Year Tree
- CF - 100513F Ilya Muromets(dp)
- 在虚拟机下安装CentOS7
- 第七章 快速排序
- 平时自己项目中用到的 CSS
- Android中的windowSoftInputMode属性详解
- TCP 与 UDP 的区别及应用场景
- cf 858F
- 深度学习(八)——fine-tuning, 李飞飞
- 9.17NOIP模拟赛
- AndroidQQ登录
- 7-26 单词长度(15 分)
- CentOS7之常用服务
- jQuery学习入门(一)
- python decorator
- Object-C的编译命令