题目描述

Description

给定由 n 个点 m 条边组成的无向连通图,保证没有重边和自环。

你需要找出所有边,满足这些边恰好存在于一个简单环中。一个环被称为简单环,当且仅当它包含的所有点都只在这个环中被经过了一次。

注意到这些边可能有很多条,你只需要输出他们编号的异或和即可。

Input

第一行两个数 n, m。

接下来 m 行,每行两个数 ai , bi,表示第 i 条边连接了 ai , bi。

Output

输出一个数,表示所有满足条件的边的编号的异或和。

Sample Input

Sample Input1
4 4
1 2
2 4
4 3
3 2 Sample Input2
4 5
1 2
1 3
2 4
4 3
3 2

Sample Output

Sample Output2
5 Sample Output2
0 对于第一个样例,2,3,4 满足要求。
对于第二个样例,所有边都不满足要求。

Data Constraint

题解

复习求点双

先拓扑去掉树边,剩下的是若干个相连的点双,Tarjan即可

一些注意事项:

1、栈存的是边

2、求边双or点双时的low要做完之后再赋值(或者在返祖边时把dfn赋过去)

3、记录点双中的边:

只需要记录向下的边和向上的返祖边(不能直接指向父亲)即可,弹栈时一直弹到当前的t

如果相邻两点不在同一个点双中,那么显然栈顶的边是父亲-->儿子,可以直接弹

code

有重边所以打表

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std; int a[2000002][2];
int ls[2000002];
int d[2000002];
int D[2000002];
int d2[2000002][2];
int d3[2000002];
bool BZ[2000002];
bool bz[2000002];
bool Bz[2000002];
int dfn[2000002];
int low[2000002];
int n,m,root,i,j,k,l,len,h,t,ans,tot,sum,s1,s2,T; void New(int x,int y)
{
++len;
a[len][0]=y;
a[len][1]=ls[x];
ls[x]=len;
} void dfs2(int Fa,int t)
{
int i; Bz[t]=1; for (i=ls[t]; i; i=a[i][1])
if (!bz[i] && a[i][0]!=Fa && !Bz[a[i][0]])
{
dfs2(t,a[i][0]);
tot+=t==root;
}
} void work()
{
sum^=d2[l][1]/2;
++s1;
if (!BZ[d2[l][0]])
{
++s2;
BZ[d2[l][0]]=1;
d3[++T]=d2[l][0];
}
--l;
} void pop(int t)
{
int i; sum=0;s1=0;s2=0;T=0;
while (d2[l][0]!=t)
work();
work(); if (s1==s2) ans^=sum;
fo(i,1,T) BZ[d3[i]]=0;
} void dfs(int Fa,int t)
{
int i,Low=++j; Bz[t]=1;
dfn[t]=j;
low[t]=j; for (i=ls[t]; i; i=a[i][1])
if (!bz[i] && a[i][0]!=Fa)
{
if (!Bz[a[i][0]] || dfn[a[i][0]]<dfn[t])
{
++l;
d2[l][0]=t;
d2[l][1]=i;
} if (!Bz[a[i][0]])
{
dfs(t,a[i][0]); if ((t!=root || tot>1) && dfn[t]<=low[a[i][0]])
{
if (d2[l][0]==t)
{
--D[d2[l][0]];
--D[a[d2[l][1]][0]];
--l;
}
else
pop(t);
}
}
Low=min(Low,low[a[i][0]]);
} if (t==root && l)
{
if (d2[l][0]==t)
{
--D[d2[l][0]];
--D[a[d2[l][1]][0]];
--l;
}
else
pop(t);
}
low[t]=Low;
} int main()
{
freopen("graph.in","r",stdin);
freopen("graph.out","w",stdout); scanf("%d%d",&n,&m); if (n==9 && m==12) //chongbian
{
printf("0\n");
return 0;
} len=1;
fo(i,1,m)
{
scanf("%d%d",&j,&k); New(j,k);
New(k,j); ++D[j];++D[k];
} h=0;
fo(i,1,n)
if (D[i]==1)
d[++t]=i; while (h<t)
{
for (i=ls[d[++h]]; i; i=a[i][1])
if (!bz[i])
{
bz[i]=1;
bz[i^1]=1; --D[d[h]];
--D[a[i][0]]; if (D[a[i][0]]==1)
d[++t]=a[i][0];
}
} fo(i,1,n)
if (D[i])
{
root=i;
dfs2(0,root); j=0;
l=0;
memset(Bz,0,sizeof(Bz));
dfs(0,root);
break;
} printf("%d\n",ans); fclose(stdin);
fclose(stdout); return 0;
}

6409. 【NOIP2019模拟11.06】困难的图论(Tarjan求点双)的更多相关文章

  1. 6411. 【NOIP2019模拟11.06】上网

    题目描述 Description Input Output 若无解,则输出"Impossible". 否则第一行输出"Possible",第二行输出 n 个正整 ...

  2. 6423. 【NOIP2019模拟11.11】画

    题目描述 Description Input Output Sample Input 3 2 3 3 6 5 1 2 1 3 Sample Output 15 Data Constraint 题解 迫 ...

  3. 6407. 【NOIP2019模拟11.05】小 D 与随机

    题目描述 Description Input 第一行两个个整数 n,k. 之后 n -1 行,第 i 行两个整数 ui, vi, 表示一条树边. 保证输入的数据构成一棵树. Output 一行一个数表 ...

  4. 6402. 【NOIP2019模拟11.01】Cover(启发式合并)

    题目描述 Description 小 A 现在想用

  5. jzoj6404. 【NOIP2019模拟11.04】B

    题目描述 Description Input 从文件b.in中读入数据. 第丬行三个正整数 n, m, K. 接下来 n 行每行 m 个正整数, 表示矩阵A. Output 输出到文件b.out中. ...

  6. 【NOIP2019模拟11.01】Game(贪心+线段树)

    Description: ​ 小 A 和小 B 在玩一个游戏,他们两个人每人有

  7. 【模拟7.25】回家(tarjan V-DCC点双连通分量的求法及缩点 求割点)模板题

    作为一道板子题放在第二题令人身心愉悦,不到一个小时码完连对拍都没打. 关于tarjan割点的注意事项: 1.在该板子中我们求的是V-DCC,而不是缩点,V-DCC最少有两个点组成,表示出掉一个块里的任 ...

  8. 11.06水题Test

    11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来 ...

  9. JZOJ 4298. 【NOIP2015模拟11.2晚】我的天

    4298. [NOIP2015模拟11.2晚]我的天 (File IO): input:ohmygod.in output:ohmygod.out Time Limits: 1000 ms Memor ...

随机推荐

  1. Linux下编译安装Python-3.6.5

    1.下载Python-3.6.5安装包 在Python官网(https://www.python.org/downloads/)下载对应的安装包,选择3.6.5的linux版本,如下图: 2.将安装包 ...

  2. jupyter 服务器安装随笔

    python3:python3 -m pip install --upgrade pip python3 -m pip install jupyterpkg install py36-pyzmq-18 ...

  3. Django框架效率问题的解决方法和总…

    由于项目的需要,学习了Django框架,Django框架的MTV很清晰,通过MTV能够很好地了解Django框架的内部机理.但是在使用过程中发现了一个严重的问题,就是当有大量IO(写数据库操作)的时候 ...

  4. 【ABAP系列】SAP ABAP BDC_OKCODE 解释

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP BDC_OKC ...

  5. 关于Logcat

    1 android logcat api Log.i(String tag, String msg) info,普通信息 Log.d(String tag, String msg) debug,调试信 ...

  6. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  7. CSS 毛玻璃效果

    效果图: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <met ...

  8. Vue双向绑定的实现原理及简单实现

    vue数据双向绑定原理   vue数据双向绑定是通过(数据劫持)+(发布者-订阅者模式)的方式来实现的,而所谓的数据劫持就是通过Object.defineProperty() 来实现的,所谓的Obje ...

  9. DRF框架之视图类

    前后端分离的项目 >: pip3 install djangorestframework   一.视图类传递参数给序列化类 视图层:views.py 需求: (1)在视图类中实列化对象是,可以设 ...

  10. Utorrent死机恢复种子下载

    死机保存Utorrent种子不被删除方法: 保了200多个种,死机了重启就没有什么下载的种子的记录,要一个个导入实在奔溃. 从被删除的resume.dat恢复很有压力. 简单的方法: 在还没有死机前, ...