题意:n m表示n个节点,m条边,下面m行a b 表示a-b点有一条有向边

题目:给定有向图,删去一个点后,可以求出该图中强连通分量中最大的点数

问:删去某点后,最大点数 最小是多少

思路:枚举删点,强连通求最大分量

mark

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<stack> #define N 1000
#define INF64 1152921504606846976
#define INF32 2147483647
#define R(x) x<<1|1
#define L(x) x<<1
#define Mid(x,y) (x+y)>>1
#define ll int
using namespace std;
vector<int>G[N],Tarjan[N];//Tarjan存下所有的强连通,其大小用 tar记录
stack<int>mystack;
int n,m,tar; inline ll Max(ll a,ll b){return a>b?a:b;}
inline ll Min(ll a,ll b){return a<b?a:b;} int DFN[N],Low[N],Time,del;//del表示当前删除的点 小写的time会redeclared
bool instack[N],vis[N];
void tarjan(int u){
int v;
DFN[u]=Low[u]=++Time;
mystack.push(u); instack[u]=true;
vis[u]=true;
for(int i=0;i<G[u].size();i++)//遍历u的所有子节点
{
v=G[u][i];
if(v==del)continue;//删点操作
if(!DFN[v])
{
tarjan(v);
Low[u]=Min(Low[u],Low[v]);
}
else if(instack[v])
Low[u]=Min(Low[u],DFN[v]);
}
if(DFN[u]==Low[u])
do
{
v=mystack.top(); mystack.pop(); instack[v]=false;
Tarjan[tar].push_back(v);
}while(u!=v);
tar++;
if(u==del){tar--;Tarjan[tar].clear();}
}
void InitTar(){
memset(DFN,0,sizeof(DFN)); memset(Low,0,sizeof(Low));
memset(instack,0,sizeof(instack));
while(!mystack.empty())mystack.pop();
for(int i=0;i<n;i++)Tarjan[i].clear();
tar=Time=0;
}
int Findmin(){
int ans=0;
for(int i=0;i<tar;i++)
ans=Max(ans,Tarjan[i].size());
if(ans<2)ans=0;
return ans;
}
int main(){
int i,j;
while(~scanf("%d%d",&n,&m)){
for(i=0;i<n;i++)G[i].clear();
while(m--)
{
int u,v; scanf("%d %d",&u,&v);
G[u].push_back(v);
}
int minm=INF32;
for(i=0;i<n;i++)//i表示删去的点,注意不要把删掉的那个点当成一个强连通
{
InitTar();
del=i;
memset(vis,0,sizeof(vis));
for(j=0;j<n;j++)
if(!vis[j] && j!=del)
tarjan(j); minm=Min(minm,Findmin()); if(!minm)break;
}
printf("%d\n",minm);
}
return 0;
}
/*
6 11
0 1
1 2
2 3
3 4
4 0
2 0
3 1
3 0
4 1
2 5
5 3 3 6
0 1
1 0
1 2
2 1
0 2
2 0 ans:
0
2
*/

ZOJ 3630 Information 强连通的更多相关文章

  1. ZOJ 3827 Information Entropy (2014牡丹江区域赛)

    题目链接:ZOJ 3827 Information Entropy 依据题目的公式算吧,那个极限是0 AC代码: #include <stdio.h> #include <strin ...

  2. ZOJ 3827 Information Entropy 水题

    Information Entropy Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/sh ...

  3. 2014 牡丹江现场赛 i题 (zoj 3827 Information Entropy)

    I - Information Entropy Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %l ...

  4. ZOJ 3795 Grouping (强连通缩点+DP最长路)

    <题目链接> 题目大意: n个人,m条关系,每条关系a >= b,说明a,b之间是可比较的,如果还有b >= c,则说明b,c之间,a,c之间都是可以比较的.问至少需要多少个集 ...

  5. ZOJ 3827 Information Entropy 水

    水 Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Informati ...

  6. zoj 3827 Information Entropy 【水题】

    Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Information ...

  7. ZOJ 3827 Information Entropy(数学题 牡丹江现场赛)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5381 Information Theory is one of t ...

  8. ZOJ 3795 Grouping 强连通分量-tarjan

    一开始我还天真的一遍DFS求出最长链以为就可以了 不过发现存在有向环,即强连通分量SCC,有向环里的每个点都是可比的,都要分别给个集合才行,最后应该把这些强连通分量缩成一个点,最后保证图里是 有向无环 ...

  9. The 2014 ACM-ICPC Asia Mudanjiang Regional

    继续复盘之前的Regional......出题者说这一套题太简单,对当时没有AK很不满......真是醉了,弱校没法活了 [A]签到题 [B]树结构,树的中心 [C]-_-/// [D]概率DP [E ...

随机推荐

  1. 「学习笔记」wqs二分/dp凸优化

    [学习笔记]wqs二分/DP凸优化 从一个经典问题谈起: 有一个长度为 \(n\) 的序列 \(a\),要求找出恰好 \(k\) 个不相交的连续子序列,使得这 \(k\) 个序列的和最大 \(1 \l ...

  2. BZOJ3289[JZYZOJP2018]: Mato的文件管理 莫队+树状数组+离散化

            描述 Description     Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号.为了防止他人偷拷,这些资料都是加密过的, ...

  3. 【20181027T3】山河令【DP套DP】

    原题 [错解] 一眼DP 哎好像能删成奇形怪状的 弃疗,主要是没时间了 [正解] 神仙DP 明显先设\(f(i,j)\)表示把\([i,j]\) 取完的最小代价 然后发现转移不了,因为可以拿很多块 但 ...

  4. [BZOJ5361]/[HDU6291]对称数

    [BZOJ5361]/[HDU6291]对称数 题目大意: 一个\(n(n\le2\times10^5)\)个结点的树,每个结点有一个权值\(a_i(a_i\le2\times10^5)\),\(m( ...

  5. bzoj 2056: gift? 高精度?

    2056: gift? 高精度? Time Limit: 10 Sec  Memory Limit: 1 MB Description   Input 输入的第一行为一个整数t. 接下来t行,每行包含 ...

  6. 【Python笔记】十分钟搞定pandas

    本文是对pandas官方网站上<10 Minutes to pandas>的一个简单的翻译,原文在这里.这篇文章是对pandas的一个简单的介绍,详细的介绍请参考:Cookbook .习惯 ...

  7. 扩展gcd codevs 1200 同余方程

    codevs 1200 同余方程 2012年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description 求关 ...

  8. python开发_linecache

    #从linecache的名称,我们可以知道该模块和cache(缓存)有关 #linecache现把文件读入到缓存中,在以后访问文件的时候,就不必要再从硬盘读取 #所以经常用于那些读取频率很高的文件还可 ...

  9. CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分

    C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...

  10. 读书笔记_Effective_C++_条款三十:了解inline的里里外外

    学过基本程序课的同学都知道,inline是内联的关键字,它可以建议编译器将函数的每一个调用都用函数本体替换.这是一种以空间换时间的做法.把每一次调用都用本体替换,无疑会使代码膨胀,但可以节省函数调用的 ...