"Problem Background"
Recently, a new infectious disease has ravaged the world. The Penglai state has also found sporadic infections to prevent the disease in the Penglai state
Widespread, the government decided to control the spread of communicable diseases at all costs. Unfortunately, as people are not yet finished
Fully aware of the epidemic, it is difficult to accurately identify the virus carriers, but also did not develop vaccines to protect susceptible populations. So
The Center for Disease Control in Penglai has decided to cut transmission routes to control disease transmission. Through the WHO (World Health
And the efforts of scientific research departments around the world, the ways and means of transmission of this emerging infectious disease have been studied
Chu, the rest of the task is for you to assist Penglai state CDC to develop an effective control method.
"Problem description"
The study shows that the spread of this kind of infectious disease has two very special properties;
The first is that it is transmitted in tree form, and a person X may be infected only by a certain person, as long as Y does not
disease, or if the transmission pathway between XY is cut off, X will not get sick.
Second, the spread of the disease is cyclical, and within a cycle of disease transmission, infectious diseases will only infect a
Instead of being transmitted to the next generation.
These properties have greatly reduced the pressure on disease Control and Prevention in Penglai, and they have got some susceptible people in the country
Map of potential routes of transmission (a tree). But the trouble is not over yet. Due to the inadequate staffing of the Peng Lai country CDC, the
And the lack of strong technology that they can only try to cut off a route of transmission during a disease transmission cycle, and
Non-controlled channels of transmission can cause more susceptible groups to be infected (that is, with people who are currently infected
The transmission pathway is connected and the connection path is not cut off by the crowd). When there is no chance of a healthy person being infected, the disease stops.
Spread. Therefore, the Penglai state CDC to develop a cut off the route of transmission in order to make as few people are infected.
Your program should target a given tree and find out the proper cut-off sequence.
"Input Format"
The first line of the input format is two integers n (1≤n≤300) and P. Next P line, each row has two integers i
and J, which means that the nodes I and J are connected by a side (meaning that there is a transmission pathway between the person I and J). Where the node
1 are patients who have already been infected.
"Output Format"
Only one row, output the total number of infected people.
Problem-solving ideas: This problem is greedy at first, but seems to have aftereffect, will find counter-examples. The right solution is search, like test instructions what we're going to do is cut one edge off each layer, so just backtrack through each layer of cut-off edges. Can be combined with optimal pruning to reduce some time: if the current number of infections exceeds the maximum answer that is currently being updated, it is clear that there is no need to search further down.
Code:
#include #include #include using namespace std;
struct point{int e; point *next;};
Point *a[305]={0},*pp,*p1;
int que[305],u[305]={0},i,n,p,minans,len,e,s; void Dfs (int k,int que[],int len,int now) {if (Now+len-1>=minans) return;//cout<<len<<endl; if (len==0) {i F (now if (Now>=minans) return, int i,que1[305],len1=0, point *p, p= (point*) malloc (point), for (i=1;i<=len;
i++) if (i!=k) {p=a[que[i]];
while (p!=0) {len1++;que1[len1]=p->e;p=p->next;}
}//printf ("%d*\n", len1); if (len1==0) {if (Now+len-1 for (i=1;i<=len1;i++) DFS (i,que1,len1,now+len-1);} int main () {freopen ("Bin.txt", "R", STD
in);
scanf ("%d%d", &n,&p);
U[1]=1; for (i=1;i<=p;i++) {scanf ("%d%d", &s,&e), if (u[e]==1) swap (s,e), pp= (point*) malloc (point), pp->
e=e;
pp->next=a[s];
A[S]=PP;
U[e]=1;
} p1= (point*) malloc (sizeof (point));
p1=a[1];minans=1111111;
while (p1!=0) {len++;que[len]=p1->e;p1=p1->next;} for (i=1;i<=len;i++) DFS (i,que,len,1); printf ("%d ", Minans);
Fclose (stdin); }