Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5783 Accepted Submission(s): 2677
Your program should find the minimum number of soldiers that Bob has to put for a given tree.
The input file contains several data sets in text format. Each data set represents a tree with the following description:
the number of nodes
the description of each node in the following format
node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifier
or
node_identifier:(0)
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500). Every edge appears only once in the input data.
For example for the tree:
the solution is one soldier ( at the node 1).
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers). An example is given in the following table:
#include<stdio.h>
#include<string.h>
#define MAX 1550
int map[MAX][MAX],vis[MAX],point[MAX];
int t;
int find(int x)
{
int i;
for(i=0;i<t;i++)
{
if(map[x][i]&&!vis[i])
{
vis[i]=1;
if(point[i]==0||find(point[i]))
{
point[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,s,n,m;
int a;
while(scanf("%d",&t)!=EOF)
{
memset(map,0,sizeof(map));
memset(point,0,sizeof(point));
for(i=0;i<t;i++)
{
scanf("%d:(%d)",&n,&m);
for(j=0;j<m;j++)
{
scanf("%d",&a);
map[n][a]=map[a][n]=1;//此处要将map[n][a]和map[a][n]同时标记
}
}
s=0;
for(i=0;i<t;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
s++;
}
printf("%d\n",s/2);//因为上边双向同时标记所以s算重复了 所以要除以2
}
return 0;
}