German Collegiate Programming Contest 2015 :

Spike the bounty hunter is tracking another criminal through space. Luckily for him hyperspace travel has made the task of visiting several planets a lot easier. Each planet has a number of Astral Gates; each gate connects with a gate on another planet. These hyperspace connections are, for obvious safety reasons, one-way only with one gate being the entry point and the other gate being the exit point from hyperspace. Furthermore, the network of hyperspace connections must be loop-free to prevent the Astral Gates from exploding, a tragic lesson learned in the gate accident of 20222022 that destroyed most of the moon.

While looking at his star map Spike wonders how many friends he needs to conduct a search on every planet. Each planet should not be visited by more than one friend otherwise the criminal might get suspicious and flee before he can be captured. While each person can start at a planet of their choosing and travel along the hyperspace connections from planet to planet they are still bound by the limitations of hyperspace travel.

Input Format

The input begins with an integer NN specifying the number of planets (0 < N \le 1000)(0<N1000). The planets are numbered from 00 to N-1N1. The following NN lines specify the hyperspace connections.

The i-th of those lines first contains the count of connections KK (0\le K\le N-1)(0KN1) from planet ii followed by KK integers specifying the destination planets.

Output Format

Output the minimum number of persons needed to visit every planet.

样例输入1
4
1 1
1 2
0
1 1
样例输出1
2
样例输入2
6
0
1 2
2 4 5
1 2
0
0
样例输出2
4

了解下DAG的最小不相交路径覆盖

板子题

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=1010;
static int map[maxn][maxn],visit[maxn],match[maxn];
int n;
bool dfs(int v)
{
     int i;
     for(i=0;i<n;i++)
     {
       if(map[v][i]&&!visit[i])
       {
          visit[i]=1;
          if(match[i]==-1||dfs(match[i]))
          {
            match[i]=v;
            return true;
          }
       }
     }
     return false;
}
            
int hungry()
{
    int i,ans=0;
    memset(match,-1,sizeof(match));
    for(i=0;i<n;i++)
    {
       memset(visit,0,sizeof(visit));
       if(dfs(i)) ans++;
    }
    return ans;
}
       
    
int main()
{
    int i,t,j,a,b,ans,m;
    scanf("%d",&n);
    memset(map,0,sizeof(map));
    for(int i=0;i<n;i++)
    {
    	int num;
    	scanf("%d",&num);
    	for(int j=0;j<num;j++){
    		int fz;
    		scanf("%d",&fz);
    		map[i][fz]=1;
		}
	}
    ans=n-hungry();
    printf("%d\n",ans);
    return 0;
}

欢迎大家加入 早起学习群,一起学习一起进步!(群号:642179511)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值