http://codeforces.com/contest/962/problem/F

求没有被两个及以上的简单环包含的边

解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加到答案中即可(正确性显然,因为bcc一定是环了,然后如果一个bcc不是简单环,那么所有边一定包含在两个简单环中)

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; vector<pii>v[N];
int dfn[N],low[N];
int ind,iscut[N],n,m;
vi ans;
struct edge{int u,v,id;};
stack<edge>s;
int bcccnt,bccno[N],ed[N];
vi bcc[N],bb[N];
void tarjan(int u,int f)
{
dfn[u]=low[u]=++ind;
int ch=;
for(int i=;i<v[u].size();i++)
{
int x=v[u][i].fi;
if(x==f)continue;
edge e={u,x,v[u][i].se};
if(!dfn[x])
{
s.push(e);
ch++;
tarjan(x,u);
low[u]=min(low[u],low[x]);
if(low[x]>=dfn[u])
{
iscut[u]=;
bcccnt++;
bcc[bcccnt].clear();
while()
{
edge now=s.top();s.pop();
ed[bcccnt]++;bb[bcccnt].pb(now.id);//printf("%d++++%d\n",bcccnt,now.id);
if(bccno[now.u]!=bcccnt){bcc[bcccnt].pb(now.u);bccno[now.u]=bcccnt;}
if(bccno[now.v]!=bcccnt){bcc[bcccnt].pb(now.v);bccno[now.v]=bcccnt;}
if(now.u==u&&now.v==x)break;
}
}
}
else if(dfn[x]<dfn[u])
{
s.push(e);
low[u]=min(low[u],dfn[x]);
}
}
if(f<&&ch==)iscut[u]=;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int a,b;scanf("%d%d",&a,&b);
v[a].pb(mp(b,i)),v[b].pb(mp(a,i));
}
ind=;
for(int i=;i<=n;i++)
if(!dfn[i])
tarjan(i,-);
// for(int i=1;i<=n;i++)printf("%d ",bccno[i]);puts("");
memset(dfn,,sizeof dfn);
for(int i=;i<=bcccnt;i++)
{
if(ed[i]==bcc[i].size()&&ed[i])
{
for(int j=;j<bb[i].size();j++)ans.pb(bb[i][j]);
}
}
sort(ans.begin(),ans.end());
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++)printf("%d ",ans[i]);
puts("");
return ;
}
/***********************
5 6
1 2
1 3
2 3
3 4
4 5
3 5
***********************/

Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  3. Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities

    http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...

  4. Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals

    http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...

  5. Educational Codeforces Round 42 (Rated for Div. 2) C

    C. Make a Square time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. Educational Codeforces Round 42 (Rated for Div. 2) B

    B. Students in Railway Carriage time limit per test 2 seconds memory limit per test 256 megabytes in ...

  7. Educational Codeforces Round 42 (Rated for Div. 2) A

    A. Equator time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  8. D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

    模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...

  9. Educational Codeforces Round 42 (Rated for Div. 2)

    A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...

随机推荐

  1. Boinformatics-2018-10-1-目录

    1.基因分析 --Using standard microbiome reference groups to simplify beta-diversity analyses and facilita ...

  2. 把当前文件夹的xlsx或xls文件合并到一个excel文件中的不同sheet中

    把当前文件夹的xlsx或xls文件合并到一个excel文件中的不同sheet中步骤如下: 把需要合并的文件放到同一个文件夹 在该文件夹中新建一个excel文件 打开新建的excel问价,把鼠标放到sh ...

  3. 20165324 Java实验一

    20165324 实验一 一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:何春江 学号:20165324 指导教师:娄嘉鹏 实验日期:2018年4月2日 实验时间:13:45 - 1 ...

  4. 格式化字符串函数sprintf

    sprintf.snprintf相关函数的主要功能是把格式化的数据写入某个字符串.如最常见的应用是将整数或浮点数转换为字符串. 1.sprintf 将格式化的数据写入字符串,并自动在末尾加上一个空字符 ...

  5. ajax示例

    ajax(Asynchronous Javascript And XML)翻译成中文就是异步的javascript和XML,即用javascript语言与服务器进行异步交互,传输的数据为XML(当然, ...

  6. bootstrap模态框嵌套、tabindex属性、去除阴影

    模态框嵌套 在开发中,遇到需要通过点击事件触发第一个模态框,触发后通过事件唤起第二个模态框,并且通过事件触发第三个模态框:即模态框嵌套. 模态框嵌套需要用一个模态框包裹所涉及嵌套的模态框,从而点击触发 ...

  7. idea操作数据库

    1.View-->>Tool Windows-->>Database. 2.点击“+”号-->>选择Data Source-->>选择需要连接的数据库类 ...

  8. 带宽、流量、CDN

    1.啥叫带宽? 1.1 带宽的概念: 在网络中的带宽往往是指一个固定的时间内,能通过的最大位数据,即数据传输率.带宽是一个计量单位,用来计量单位时间内传输的数据量的多少. 1.2 计量单位: 这个数据 ...

  9. js的同步异步

    由于js没有多线程,所以处理多任务的时候,可以用异步回调来解决.js中setTimeout.setInterval.ajax(jq中可以选择同步或异步)均会开启异步.遇到异步模块,会将其推入值任务队列 ...

  10. 【android】开发笔记系列UI篇

    弹出View添加阴影效果 系统自带就有,在android studio上直接写入背景颜色 android:background="@android:drawable/dialog_holo_ ...