题意

给出一个有向图,
A任务:求最少需要从几个点送入信息,使得信息可以通过有向图走遍每一个点
B任务:求最少需要加入几条边,使得有向图是一个强联通分量

思路

任务A,比较好想,可以通过tarjan缩点,求出入度为0的点的个数
任务B
一开始以为任务A,B没有关系
其实是入度为0的点的个数、出度为0的点的个数的最大值。
因为任务B要求在任意学校投放软件使得所有学校都能收到,所以很明显是需要整张图形成一个环,而环中所有节点入度和出度都不为0,所以需要把所有入度和出度的点度数增加。

(注意判断本身就全联通的情况

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> /* ⊂_ヽ
  \\ Λ_Λ 来了老弟
   \('ㅅ')
    > ⌒ヽ
   /   へ\
   /  / \\
   レ ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
'ノ )  Lノ */ using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c); const ll oo = 1ll<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;} /*-----------------------showtime----------------------*/ const int maxn = ;
vector<int>mp1[maxn],mp2[maxn]; int dfn[maxn],low[maxn],vis[maxn],col[maxn];
int dp[maxn][maxn], in[maxn];
stack<int>st;
int tot = ,nn = ;
void tarjan(int u){
dfn[u] = low[u] = ++tot; st.push(u); vis[u] = ;
for(int i=; i<mp1[u].size(); i++){
int v = mp1[u][i];
if(dfn[v] == ){
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if(vis[v]){
low[u] = min(low[u], dfn[v]);
}
}
if(low[u] == dfn[u]){
nn++;
while(!st.empty()){
int x = st.top(); st.pop();
col[x] = nn;
vis[x] = ;
if(x == u) break;
}
}
} int main(){
int n; scanf("%d", &n);
rep(i, , n){
int x; while(~scanf("%d", &x) && x) mp1[i].pb(x); } rep(i, , n) if(!dfn[i]) tarjan(i);
rep(i, , n) {
int u = col[i];
for(int j=; j<mp1[i].size(); j++){
int v = col[mp1[i][j]];
dp[u][v] = ;
}
}
rep(i, , nn) {
rep(j, , nn) { if(i == j) continue;
if(dp[i][j]) mp2[i].pb(j), in[j]++;
}
} int ansa = ,c1=,c2=;
rep(i, , nn) {
if(in[i] == ) ansa++,c1++;
if(mp2[i].size() == ) c2 ++;
}
if(nn == ) c1 = c2 = ;
printf("%d\n%d\n", ansa,max(c1, c2));
return ;
}

P2746 [USACO5.3]校园网Network of Schools tarjan 缩点的更多相关文章

  1. P2746 [USACO5.3]校园网Network of Schools [tarjan缩点]

    题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 BB 在 AA 学校的分发列表中,AA 也不一定在 BB 学校的列表中. ...

  2. P2746 [USACO5.3]校园网Network of Schools(Tarjan)

    P2746 [USACO5.3]校园网Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 ...

  3. 洛谷 P2746 [USACO5.3]校园网Network of Schools (Tarjan,SCC缩点,DAG性质)

    P2746 [USACO5.3]校园网Network of Schools https://www.luogu.org/problem/P2746 题目描述 一些学校连入一个电脑网络.那些学校已订立了 ...

  4. 洛谷 P2746 [USACO5.3]校园网Network of Schools 解题报告

    P2746 [USACO5.3]校园网Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作"接受学校&q ...

  5. P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools

    P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学 ...

  6. 洛谷 P2746 [USACO5.3]校园网Network of Schools schlnet Tarjan强连通分量

    schlnet ★★★   输入文件:schlnet.in   输出文件:schlnet.out   简单对比时间限制:1 s   内存限制:128 MB 描述 一些学校连入一个电脑网络.那些学校已订 ...

  7. 洛谷P2746 [USACO5.3]校园网Network of Schools

    题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要写 ...

  8. 洛谷 P2746 [USACO5.3]校园网Network of Schools

    题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要写 ...

  9. 【luogu P2746 [USACO5.3]校园网Network of Schools】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2812 注意:判断出入度是否为0的时候枚举只需到颜色的数量. 坑点:当只有一个强连通分量时,不需要再添加新边. ...

随机推荐

  1. Vue中beforeRouterEnter的应用

    一般判断从哪个页面进入时需要判断路由,用到了beforeRouteEnter方法. 注意:在在内部获取不到外部的this,方法.变量等都获取不到.但是vm.XXXXX可以获取到 beforeRoute ...

  2. 【iOS】代码片段库

    若在某个 Objective-C 的实现文件中输入 init,Xcode 会自动列出一系列备选项,如图所示: Xcode 自动加入的这段代码源自代码片段库(code snippet library), ...

  3. .Net Core CLR FileFormat Call Method( Include MetaData, Stream, #~)

    .Net Core  CLR PE 文件启动方法,找到函数入口点,调用整个.Net 程式宿主. 使用方法:可以利用Visual Studio新建一个控制台应用程序,然后生成DLL,替换掉本程序DLL, ...

  4. KD-tree 专题「Hide and Seek · 巧克力王国」

    Lockey的瞎理解 抄了一遍板子又水了俩题,感觉对KD-tree 稍稍理解了一点儿,唠叨一下(二维的KD-tree),如有错误请指出(Lockey 洗脸恭听) 普通平衡树维护的是一维的序列,但对于二 ...

  5. MRCPv2在电信智能语音识别业务中的应用

    1. MRCPv2协议简介 媒体资源控制协议(Media Resource Control Protocol, MRCP)是一种基于TCP/IP的通讯协议,用于客户端向媒体资源服务器请求提供各种媒体资 ...

  6. Vector的一些事

    1.利用数组对vector进行初始化方法 当然有许多方法,这里就讲一种.原因简单,其他方式请参见这个博文:http://www.cplusplus.me/1112.html , , , , -}; v ...

  7. alluxio源码解析-rpc调用概述-client和worker之间的block模块的通讯架构(netty版本)(3)

    (1.8版本)client和worker之间的block模块的通讯架构 block作为alluxio文件读取或者存储的最小基本单位,都是通过BlockOutStream和BlockInputtream ...

  8. abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十三)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  9. 物流运输trans「ZJOI2006」

    [题目描述] 物流公司要把一批货物从码头\(A\)运到码头\(B\).由于货物量比较大,需要\(n\)天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运 ...

  10. Java学习|HTTP请求头

    https://www.cnblogs.com/honghong87/articles/6941436.html 常见http请求报文头属性      Accept:告诉服务端,客户端接受什么类型的响 ...