题意:找三条同起点同终点的不相交的路径

题解:用tarjan的思想,记录两个low表示最小和次小的dfs序,以及最小和次小的位置,如果次小的dfs序比dfn小,那么说明有两条返祖边,那么就是满足条件的答案

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#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")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#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 ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#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 Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=50000+10,inf=0x3f3f3f3f; vi v[N],road;
int dfn[N],low[N][2],fa[N];
pii pos[N][2];
int ind;
bool ok;
void pr()
{
printf("%d",road.size());
for(int i=0;i<road.size();i++)printf(" %d",road[i]);puts("");
road.clear();
}
void tarjan(int u,int f)
{
if(ok)return ;
dfn[u]=low[u][0]=low[u][1]=++ind;
for(int i=0;i<v[u].size();i++)
{
int x=v[u][i];
if(x==f)continue;
if(!dfn[x])
{
fa[x]=u;
tarjan(x,u);
if(low[x][1]<low[u][0])
{
low[u][1]=low[u][0];
pos[u][1]=pos[u][0];
low[u][0]=low[x][1];
pos[u][0]=pos[x][1];
}
else if(low[x][1]<low[u][1])
{
low[u][1]=low[x][1];
pos[u][1]=pos[x][1];
}
if(low[x][0]<low[u][0])
{
low[u][1]=low[u][0];
pos[u][1]=pos[u][0];
low[u][0]=low[x][0];
pos[u][0]=pos[x][0];
}
else if(low[x][0]<low[u][1])
{
low[u][1]=low[x][0];
pos[u][1]=pos[x][0];
}
}
else if(dfn[x]<dfn[u])
{
if(dfn[x]<low[u][0])
{
low[u][1]=low[u][0];
pos[u][1]=pos[u][0];
low[u][0]=dfn[x];
pos[u][0]=mp(u,x);
}
else if(dfn[x]<low[u][1])
{
low[u][1]=dfn[x];
pos[u][1]=mp(u,x);
}
}
}
if(low[u][1]<dfn[u]&&!ok)
{
ok=1;
printf("%d %d\n",u,pos[u][1].se);
for(int now=u;now!=pos[u][1].se;now=fa[now])road.pb(now);
road.pb(pos[u][1].se);
pr();
road.pb(pos[u][1].se);
for(int now=pos[u][1].fi;now!=u;now=fa[now])road.pb(now);
road.pb(u);
reverse(road.begin(),road.end());
pr();
for(int now=pos[u][1].se;now!=pos[u][0].se;now=fa[now])road.pb(now);
road.pb(pos[u][0].se);
for(int now=pos[u][0].fi;now!=u;now=fa[now])road.pb(now);
road.pb(u);
reverse(road.begin(),road.end());
pr();
// for(int i=1;i<=8;i++)printf("%d %d\n",i,fa[i]);
// printf("%d %d %d %d %d %d %d %d---\n",u,dfn[u],low[u][0],pos[u][0].fi,pos[u][0].se,low[u][1],pos[u][1].fi,pos[u][1].se);
return ;
}
}
int main()
{
freopen("grand.in","r",stdin);
freopen("grand.out","w",stdout);
int T;scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
dfn[i]=low[i][0]=low[i][1]=fa[i]=0;
v[i].clear();
}
ind=0;
for(int i=0,x,y;i<m;i++)
{
scanf("%d%d",&x,&y);
v[x].pb(y),v[y].pb(x);
}
ok=0;
for(int i=1;i<=n;i++)
if(!dfn[i])
tarjan(i,-1);
if(!ok)puts("-1");
}
return 0;
}
/********************
1
8 9
1 2
1 3
4
2 5
3 6
4 7
5 8
6 8
7 8
********************/

2017-2018 ACM-ICPC, NEERC, Northern Subregional ContestG - Grand Test的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】---暑假三校训练

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D Problem D. Distribution in Metagonia Input ...

  4. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  5. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  6. 模拟赛小结:2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest 2019年10月11日 15:35-20:35(Solved 8,Penalty 675 ...

  7. 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest (9/12)

    $$2015-2016\ ACM-ICPC,\ NEERC,\ Northern\ Subregional\ Contest$$ \(A.Alex\ Origami\ Squares\) 签到 //# ...

  8. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  9. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

随机推荐

  1. How do I extract a single column from a data.frame as a data.frame

    Say I have a data.frame: df <- data.frame(A=c(10,20,30),B=c(11,22,33), C=c(111,222,333))  A  B  C ...

  2. 使用路由传参时,query与params的区别!

    query 1:参数会在地址栏显示 2:参数不需要在路由的path后接:args1/:args2 3:获取参数用this.$route.query.args1 params 1:参数需要在路由的pat ...

  3. kubernetes 实战4_命令_Configure Pods and Containers

    Configure Service Accounts for Pods A service account provides an identity for processes that run in ...

  4. 自定义Exception:MVC抛出自定义异常,并以Json方式返回

    相关链接 优点: 可以统一处理所有页面的异常,对所有需要返回json数据的异常,都用同样的方法throw new DVMException().页面展示,controller的错误处理方式一样 节省编 ...

  5. 4、Ansible(tags、roles)

    Tags https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html http://www.zsythink.net/ ...

  6. 4、My Scripts

    脚本目录列表 1.在windows编写的shell脚本利用dos2unix命令格式化一下(P308) 2.bash命令参数调试(P309) 3.使用set命令调试部分脚本内容(P312) 4.开发脚本 ...

  7. js字符串与十六进制相互转换

    1.字符串(汉字)转换为十六进制 主要使用字符串.charCodeAt()方法,此方法返回一个字符的Unicode值,再用toString(16)方法,该方法是先将数字对象转换为二进制,再把二进制转化 ...

  8. Unity--game

    打怪兽--头像状态 Git :https://github.com/vinieo/attck 打怪兽--背景音乐音量 Git :https://github.com/vinieo/ack_bgm 小球 ...

  9. 2017"百度之星"程序设计大赛 - 初赛(A) 01,05,06

    小C的倍数问题    Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 32768/32768 K (Java/Others) Problem ...

  10. PCA-主成分分析(Principal components analysis)

    来自:刘建平 主成分分析(Principal components analysis,以下简称PCA)是最重要的降维方法之一. 1. PCA的思想 PCA顾名思义,就是找出数据里最主要的方面,用数据里 ...