我就是想骗一骗访问量

先Tarjan搞出来所有的强连通分量

正向连边 反向连边 topsort一发  搞出来每个点可以到哪些点 和哪些点可以到这个点

对于每条边 与一下  就是答案

//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
const int N=,M=N*N;
int n,m,T,jy,ans,r=;
int low[N],dfn[N],cnt,stk[N],vis[N],p[N],top;
set<int>s;
struct Edge{
bitset<N>f[N];
int mp[N][N],in[N];
void topsort(){
queue<int>q;
for(int i=;i<=T;i++)for(int j=;j<=T;j++)if(mp[i][j])in[j]++;
for(int i=;i<=T;i++)if(!in[i])q.push(i);
while(!q.empty()){
int t=q.front();q.pop();
for(int v=;v<=T;v++)if(mp[t][v]){
in[v]--,f[v]|=f[t];
if(!in[v])q.push(v);
}
}
}
}e[];
struct Road{int x,y;Road(int X=,int Y=):x(X),y(Y){};}rd[M];
void tarjan(int x){
low[x]=dfn[x]=++cnt,stk[++top]=x;vis[x]=;
for(int v=;v<=n;v++)if(e[].mp[x][v]){
if(!dfn[v])tarjan(v),low[x]=min(low[x],low[v]);
else if(vis[v])low[x]=min(low[x],dfn[v]);
}if(low[x]==dfn[x]){T++;do{jy=stk[top--],vis[jy]=;p[jy]=T;e[].f[T][jy]=e[].f[T][jy]=;}while(jy!=x);}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)scanf("%d%d",&rd[i].x,&rd[i].y),e[].mp[rd[i].x][rd[i].y]=;
for(int i=;i<=n;i++)if(!dfn[i])tarjan(i);
for(int i=;i<=m;i++)if(p[rd[i].x]!=p[rd[i].y])
e[].mp[p[rd[i].x]][p[rd[i].y]]=e[].mp[p[rd[i].y]][p[rd[i].x]]=;
e[].topsort();e[].topsort();
for(int i=;i<=m;i++){
int t=(int)(e[].f[p[rd[i].x]]&e[].f[p[rd[i].y]]).count();
if(ans<t)s.clear(),ans=t,s.insert(i);
else if(ans==t)s.insert(i);
}
printf("%d\n%d\n",ans,(int)s.size());
for(set<int>::iterator it=s.begin();it!=s.end();it++,r++)printf("%d%c",*it,r==s.size()?'\n':' ');
}

BZOJ 4304 tarjan+topsort+bitset的更多相关文章

  1. BZOJ.2208.[JSOI2010]连通数(bitset Tarjan 拓扑)

    题目链接 先缩点,对于scc之间贡献即为szscc[i]*szscc[j] 用f[i][j]表示scci是否能到sccj 拓扑排序,每次把now的f或上to的f 用bitset优化 //63888kb ...

  2. Luogu3119 草鉴定-Tarjan+Topsort

    Solution 简单的$Tarjan$题. 有大佬现成博客 就不写了 → 传送门 Code #include<cstdio> #include<cstring> #inclu ...

  3. 【UVA11324】 The Largest Clique (Tarjan+topsort/记忆化搜索)

    UVA11324 The Largest Clique 题目描述 给你一张有向图 \(G\),求一个结点数最大的结点集,使得该结点集中的任意两个结点 \(u\) 和 \(v\) 满足:要么 \(u\) ...

  4. Tarjan+topsort(DP)【P3387】 [模板]缩点

    Description 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点,但是,重复经过的点,权值只计算一次 ...

  5. [JSOI2010]连通数 (dfs或tarjan或bitset)+bitset学习

    题目描述 输入格式 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i行第j列的1表示顶点i到j有边,0则表示无边. 输出格式 输出一行一个整数,表示该图的连通数. 样例 样 ...

  6. [bzoj 3687]简单题 bitset的运用

    题意 给定一个正整数集,求所有子集算术和的异或和   题解 每次加入一个元素x,用原集合a xor (a<< x) 然后每一个值统计一下 bitset看起来很优越,是一个能位运算的布尔数组 ...

  7. BZOJ 3687: 简单题 bitset

    3687: 简单题 Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 小呆开始研究集合论了,他 ...

  8. bzoj 3687 简单题——bitset

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3687 关于 bitset :https://blog.csdn.net/snowy_smil ...

  9. bzoj 1123 tarjan求割点

    #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...

随机推荐

  1. 爬虫----Web_WeChat

    流程: 打开的web_wechat,就有出现二维码,在network中,name中login?loginicon中,status的状态是pending,pending的意思是前端发送了一个请求,但是还 ...

  2. IDLE in Python (Ubuntu)

    To lauch IDLE in the Current Woking Directory >>> usr/bin/idle3 Alt + n  # next command Alt ...

  3. 以位为单位存储标志-共用体-union

    一.程序的结构如下: typedef union _KEYST     {         struct         {             uint8 Key1_Flag :1;//表示第0 ...

  4. 如何通过js在子页面调用父页面元素的click事件

    //获取父页面的某个元素var node = window.parent.document.getElementById("btnReturn");//调用该元素的Click事件 ...

  5. 使用Mybatis进行连表查询、left join---https://blog.csdn.net/jinzhencs/article/details/51980518

    使用Mybatis进行连表查询.left join https://blog.csdn.net/jinzhencs/article/details/51980518

  6. NYOJ 832 合并游戏

    合并游戏 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 大家都知道Yougth除了热爱编程之外,他还有一个爱好就是喜欢玩.某天在河边玩耍的时候,他发现了一种神奇的石 ...

  7. 数论结论 nefu 702

    Given a prime p (p<108),you are to find min{x2+y2},where x and y belongs to positive integer, so ...

  8. 简单svg动画

    一.将svg嵌入到html中 svg是指可伸缩矢量图形,它使用XML格式定义图像.在html中可以使用<svg>标签直接嵌入svg代码,例如: <svg version=" ...

  9. 对象和变量的并发访问synchronized解析以及死锁分析排查

    一.synchronized java并发编程中存在“非线程安全"问题.“非线程安全"是指发生在多个线程对同一个对象中的实例变量并发访问时,产生的”脏读“现象,使用synchron ...

  10. MySQL慢日志切割邮件发送脚本

    #!/bin/bashtime=`date -d yesterday +"%Y-%m-%d"`slowlog='/usr/local/percona/data/slow.log'# ...