Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
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的更多相关文章
- 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 ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))
模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...
- Educational Codeforces Round 42 (Rated for Div. 2)
A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...
随机推荐
- 查看Oracle相关日志 ADRCI
ADRCI 进去以后 show home
- DevOps简单介绍
jenkins作为测试环境代码发布工具,sonar作为静态代码检查工具,idea作为开发工具,jira作为缺陷管理平台,upstream作为code review工具(正在研究).DevOps最近比较 ...
- 负载均衡技术在CDN中发挥着重要作用
转载地址:http://www.qicaispace.com/gonggao/server/page01/info07.asp CDN是一个经策略性部署的整体系统,能够帮助用户解决分布式存储.负载均衡 ...
- [.net基础]访问修饰符
标题:[.net基础]访问修饰符 一.前言 基础掌握不牢固啊,所以记录下来. 二.方法访问修饰符Internal (1).创建工程ParentAndSon (2).添加类ModelA namespac ...
- mouseover 有一个多次触发的问题
mouseover 有一个多次触发的问题 需要注意 由于浏览器的冒泡行为.造成如果在一个DIV元素上同时定义了mouseover,mouseout的时候,当鼠标移动到DIV中的child子元素的时候, ...
- Java-Minor GC、Major GC、Full GC
Minor GC: 回收年轻代(Young)空间,包括Eden区.Survivor区. JVM无法为一个新对象分配空间时,比如eden区满了,就会触发Minor GC. Major GC: 清理永久代 ...
- 2017阿里C++研发工程师-校招-单词匹配
题目描述 给一个字符串, 然后给一个字典. 把字符串分解成字典里的单词组成的句子, 请输出所需空格最少的方案.并输出该方案. 样例 例如: 字符串为: str="ilikealibaba&q ...
- Java Swing简单的加法器
package test; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class FrameDe ...
- Java学习笔记-方法引用
方法引用(Method Reference) 上一篇中记录了Lambda表达式,其可以创建匿名方法.当Lambda表达式只是调用一个存在的方法时,可以采用方法引用(JDK8具有的特性).如下: pub ...
- mysql分库分表(二)
mysql分库分表 参考: https://www.cnblogs.com/dongruiha/p/6727783.html https://www.cnblogs.com/oldUncle/p/64 ...