time limit per test : 1.5 seconds
memory limit per test : 256 megabytes

分数:2800

Once upon a time there lived a good fairy A. One day a fine young man B came to her and asked to predict his future. The fairy looked into her magic ball and said that soon the fine young man will meet the most beautiful princess ever and will marry her. Then she drew on a sheet of paper n points and joined some of them with segments, each of the segments starts in some point and ends in some other point. Having drawn that picture, she asked the young man to erase one of the segments from the sheet. Then she tries to colour each point red or blue so, that there is no segment having points of the same colour as its ends. If she manages to do so, the prediction will come true. B wants to meet the most beautiful princess, that’s why he asks you to help him. Find all the segments that will help him to meet the princess.

Input

The first input line contains two integer numbers: n — amount of the drawn points and m — amount of the drawn segments (1≤n≤104,0≤m≤104)(1 ≤ n ≤ 10^4, 0 ≤ m ≤ 10^4)(1 ≤ n ≤ 104, 0 ≤ m ≤ 104). The following m lines contain the descriptions of the segments. Each description contains two different space-separated integer numbers v,u(1≤v≤n,1≤u≤n)v, u (1 ≤ v ≤ n, 1 ≤ u ≤ n)v,u(1 ≤ v ≤ n, 1 ≤ u ≤ n) — indexes of the points, joined by this segment. No segment is met in the description twice.

Output

In the first line output number k — amount of the segments in the answer. In the second line output k space-separated numbers — indexes of these segments in ascending order. Each index should be output only once. Segments are numbered from 1 in the input order.

Examples
Input

4 4
1 2
1 3
2 4
3 4

Output

4
1 2 3 4

Input

4 5
1 2
2 3
3 4
4 1
1 3

Output

1
5

题意:
给定一张图,你可以选择一条边删去,使得整个图变为一个二分图。求出所有这样的边。

题解:
我们可以先按照给图染色的方式遍历整个图。我们将边分成这几类,一种是树边,一种是非树边,一种是坏边(连接两个同色的点),一种是非坏边(非树边中连接两个不同色的点)。如果坏边的数量等于0,那么我们可以删除所有的非树边。如果坏边的数量等于1,那么我们可以删除所有的坏边。如果坏边的数量大于1,我们可以删除任意一条非树边。
现在只要处理出这些东西就行了。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
struct edge{int to,nt,w;
}e[100004];
int ne,h[10004];
int flag,vis[10004],brk[100004];
ll f[10004],col[10004];
void add(int u,int v,int w){e[++ne].to=v;e[ne].w=w;e[ne].nt=h[u];h[u]=ne;
}
void dfs(int x,int fa){vis[x]=1;for(int i=h[x];i;i=e[i].nt){if(e[i].to==fa||col[x]<col[e[i].to])continue;else if(!vis[e[i].to]){col[e[i].to]=col[x]+1;dfs(e[i].to,x);f[x]+=f[e[i].to];brk[i]=f[e[i].to];}else if((col[x]-col[e[i].to])%2==1){f[x]--;f[e[i].to]++;}else{f[x]++;f[e[i].to]--;brk[i]=1;flag++;}}
}
int main(){scanf("%d%d",&n,&m);ne=0;flag=0;memset(h,0,sizeof(h));for(int i=1;i<=m;i++){int u,v;scanf("%d%d",&u,&v);add(u,v,i);add(v,u,i);}for(int i=1;i<=n;i++){if(!vis[i])dfs(i,0);}if(!flag){printf("%d\n",m);for(int i=1;i<=ne;i+=2){printf("%d ",e[i].w);}puts("");}else{vector<int>ans;ans.clear();for(int i=1;i<=ne;i++){if(brk[i]==flag){ans.push_back(e[i].w);}}printf("%d\n",ans.size());for(int i=0;i<ans.size();i++){printf("%d ",ans[i]);}if(ans.size())puts("");}return 0;
}

[codeforces19E]Fairy相关推荐

  1. codeforces19E Fairy

    https://codeforces.com/contest/19/problem/E 这题怎么2900分啊...可能以前dfs树的做法还不是well known,现在感觉最多2500了 显然这题就是 ...

  2. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

  3. 【CodeForces19E】Fairy

    Description 给定 n 个点,m 条边的无向图,可以从图中删除一条边,问删除哪些边可以使图变成 一个二分图. Input 第 1 行包含两个整数 n,m.分别表示点数和边数. 第 2 到 m ...

  4. Anton and Fairy Tale CodeForces - 785C(二分+思维)

    Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right ...

  5. F - Fairy, the treacherous mailman

    菜鸡复健 F. Fairy, the treacherous mailman time limit per test1 second memory limit per test256 megabyte ...

  6. Anton and Fairy Tale

    Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right ...

  7. Fairy tale(BFS + 大模拟)

    一.题目链接: Fairy tale 二.题目大意: 给你一个N × N 的地图,图上的每个点有四种方向(E W S N),代表着移动方向. 在 t = 0 时,saya 在 (1, 1),treas ...

  8. CodeForces 19E 仙女fairy

    CF19E 话说标题"仙女",好骚啊.... 这道题的题面核心是图论二分图.满足删除一条边,可以形成一张二分图.求可以删除的边数,并输出是那些边. 出题人非常良心的给出了前六十分的 ...

  9. 隐私公链背景的FAIRY SWAP,让DEX更进一步

    Fairyswap即将开启冷启动.Fairyswap作为隐私公链龙头Findora推出的首个Dex,吸引了不少原Findora社区群体的关注,本文将带大家体验Fairyswap的创新,以及我们用户现在 ...

最新文章

  1. 印度Thermax携FRENELL执行亚洲首个集成太阳能热电厂
  2. wincc 关闭弹出窗口C语言,退出WINCC操作画面时弹出对话框要求输入用户名和密码-工业支持中心-西门子中国...
  3. Oracle启用和禁用触发器
  4. 前端学习(3150):react-hello-react之DoM的diff算法
  5. python是开源工具吗_微软最强 Python 自动化工具开源了!不用写一行代码
  6. 输入这个命令之后,FinalShell连接不上地推主机了
  7. 关于计算机工作的诗歌,提高计算机工作及上网效率的方法
  8. JSON and Microsoft Technologies(翻译)
  9. [日期]字符串转Data对象
  10. 计算机,通信职称考试,2017年通信工程师考试科目介绍
  11. Enzo Life Sciences/艾美捷丨线粒体/胞浆分离试剂盒
  12. 企业微信异常java.security.InvalidKeyException:illegal Key Size的解决方案,提供jce_policy-8下载
  13. Kubernates(k8s)工作负载之工作负载资源
  14. win7系统如何添加打印机服务器,怎样如何添加打印机驱动步骤
  15. 利用三角形三条边求三角形面积
  16. 自定义view系列---刮刮乐的实现
  17. 【CC】| 创建三维模型教程
  18. linux+命令行粘贴不执行,在linux命令行粘贴命令后果
  19. html5道歉模板,给朋友的道歉信模板5篇2020
  20. 关于「付费合集」的说明

热门文章

  1. 微信小程序怎么添加底部菜单按钮
  2. 【Monkey Run】Excel编程 VBA
  3. java无响应_Java HttpClient请求无响应解决方案
  4. 【判断一个文件是否为 excel 文件的正则表达式】
  5. 食肉动物和食草动物的双眼分布不同的原因
  6. 云消防大数据_2020年刚需系列专题之智慧消防大数据平台建设方案 智慧消防云平台项目 解决方案,一查就有...
  7. Python程序题练习
  8. Android自定义控件--仿安全卫士中的一键加速【圆形进度条】
  9. LPC55S69开发笔记
  10. java解析8583报文55域