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<N≤1000). The planets are numbered from 00 to N-1N−1. 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)(0≤K≤N−1) 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)
上一篇: 2015-2016 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2015) Goblin Garden Guards (数论)
下一篇: 【Codeforces】2015-2016 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2015) A Adjoin the Netwo
推荐阅读
-
Nordic Collegiate Programming Contest 2017 题解
-
2015-2016 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2015) Goblin Garden Guards (数论)
-
German Collegiate Programming Contest 2015 :
-
【Codeforces】2015-2016 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2015) A Adjoin the Netwo
-
Nordic Collegiate Programming Contest 2019 部分题解
-
ICPC Arab Collegiate Programming Contest 2013(部分题解)
-
L Clock Master(2020 China Collegiate Programming Contest Weihai Site)补题
-
2015 ACM Amman Collegiate Programming Contest I.Bahosain and Digits【思维+暴力枚举】
-
2011-2012 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2011)Problem A Robots on a grid(迷宫dp)
-
Nordic Collegiate Programming Contest 2015--Disastrous Downtime