nyoj 120: 校园网络

题目链接

要加边使一个图成为一个强连通分量,只需加max(出度为0的点数,入度为0的点数)条边(可以不使用tarjan算法)。题目数据有点弱,网上一些人所谓 结果 = 出度为0的点的数量+入度为0的点的数量 是错的,代码尾提供一种可以hack的数据

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N=110;
int n,T;
int in[N],out[N];

void init()
{
    memset(in,0,sizeof(in));
    memset(out,0,sizeof(out));
}


int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        init();
        int v;
        for(int i=1;i<=n;i++)
            while(scanf("%d",&v)&&v)
                in[i]++,out[v]++;
        int ans1=0,ans2=0;
        for(int i=1;i<=n;i++)
        {
            if(!in[i]) ans1++;
            if(!out[i]) ans2++;
        }
        cout<<max(ans1,ans2)<<endl;
    }
}
/*
1
3
2 3 0
0
0
*/
View Code

 

转载于:https://www.cnblogs.com/Just--Do--It/p/6442873.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值