NIOP 2003 infectious Disease Control (oops my calcium oxide pits a long search problem)

Source: Internet
Author: User

/*I think it's right, but I don't think there's going to be a 70-point sentence.*/#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<vector>#defineMAXN 310using namespacestd;intinit () {intx=0;Chars=GetChar ();  while(s<'0'|| S>'9') s=GetChar ();  while(s>='0'&&s<='9') {x=x*Ten+s-'0'; s=GetChar ();} returnx;}intN,M,C[MAXN],SON[MAXN][MAXN],SUM[MAXN],G[MAXN][MAXN],F[MAXN];intsize[maxn],fa[maxn],ans=0x3f3f3f3f; Vector<int>SO[MAXN];voidBuild (inti) {F[i]=1;  for(intj=0; J<so[i].size (); j + +)      {          intson=So[i][j]; if(f[son]==0) {Fa[son]=i; son[i][++sum[i]]=Son;          Build (Son); }      }}voidDfs (intIintnum) {    int Get=0; if(Num>=ans)return; intsum=0;  for(intj=1; j<=size[i];j++)      if(f[fa[g[i][j]]]==0) {Sum++; Get=1; }      Elsef[g[i][j]]=1;  for(intj=1; j<=size[i];j++)      {          if(f[g[i][j]]==0) {F[g[i][j]]=1; Dfs (i+1, num+sum-1); F[G[I][J]]=0;  for(intk=1; k<=sum[g[i][j]];k++) F[son[g[i][j]][k]]=0; }      }    if(Get==0) {ans=min (ans,num); return; }}intMain () {n=init (); m=init (); intx, y; c[1]=1;  for(intI=1; i<=m;i++) {x=init (); y=init ();        So[x].push_back (y);      So[y].push_back (x); } Build (1); Memset (F,0,sizeof(f)); size[1]=1; g[1][1]=1;  for(intI=1; i<=n;i++)       for(intj=1; j<=sum[i];j++)        {          intt=c[i]+1; C[SON[I][J]]=T; g[t][++size[t]]=Son[i][j]; } Dfs (2,1); printf ("%d\n", ans); return 0;}
/*after looking at the solution of the sense of thinking and their own is almost just so much clearer (well, not only clear ...). 100 min-)*/#include<iostream>#include<cstdio>#include<cstring>#include<vector>#defineMAXN 310using namespacestd;intinit () {intx=0;Chars=GetChar ();  while(s<'0'|| S>'9') s=GetChar ();  while(s>='0'&&s<='9') {x=x*Ten+s-'0'; s=GetChar ();} returnx;}intN,M,MAX_C,SON[MAXN][MAXN],SUM[MAXN],C[MAXN];intans=0x3f3f3f3f, num=1, F[maxn];vector<int>SO[MAXN];voidBuild (inti) {F[i]=1;  for(intj=0; J<so[i].size (); j + +)      {          intson=So[i][j]; if(f[son]==0) {son[i][++sum[i]]=Son;          Build (Son); }      }      }voidDfs (intp) {    int Get=0; if(Num>=ans)return; intsum=0;  for(intI=1; i<=n;i++)      if(c[i]==p) for(intj=1; j<=sum[i];j++)          {              Get=1; C[SON[I][J]]=p+1; Num++; } num--;  for(intI=1; i<=n;i++)      if(c[i]==p+1) {C[i]=0; Dfs (P+1); C[i]=p+1; } num++;  for(intI=1; i<=n;i++)      if(c[i]==p+1) {C[i]=0; num--; }    if(Get==0) {ans=min (ans,num); return; }}intMain () {n=init (); m=init (); intx, y; c[1]=1;  for(intI=1; i<=m;i++) {x=init (); y=init ();        So[x].push_back (y);      So[y].push_back (x); } Build (1);  for(intI=1; i<=n;i++)       for(intj=1; j<=sum[i];j++)        {          intt=c[i]+1; Max_c=Max (max_c,t); C[SON[I][J]]=T; } memset (c,0,sizeof(c)); c[1]=1; Dfs (1); printf ("%d\n", ans); return 0;}

NIOP 2003 infectious Disease Control (oops my calcium oxide pits a long search problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.