Spoj Netadmin_smart Network Administrator

Source: Internet
Author: User

For a diagram, some points need to be connected to 1 points individually in a certain color line, asking how to arrange the colors that make the whole graph the most color of the road with the least color.

Obviously, the binary enumeration and then color is actually the flow, equivalent to each edge limit a current two points of traffic value, determine whether the full stream can be.

Summon Code June:

#include <iostream>#include<cstdio>#include<cstring>#defineMAXN 555#defineMAXM 333333using namespacestd;Const intinf=~0U>>2;intTo[maxm],next[maxm],c[maxm],first[maxm],edge;inttag[maxn],d[maxn],tag=520;intQ[maxn],bot,top;BOOLCAN[MAXN];intN,m,k,t,h,s,t,house,ans,boder;voidAddedge (intUintV) {Edge++; To[edge]=v,c[edge]=1, next[edge]=first[u],first[u]=Edge; Edge++; To[edge]=u,c[edge]=1, next[edge]=first[v],first[v]=Edge;}void_input () {scanf ("%d%d%d",&n,&m,&k); Edge=-1;  for(intI=0; i<=n; i++) first[i]=-1; S=1, t=0, house=K;  while(k--) {scanf ("%d",&h);    Addedge (h,t); } boder=Edge;  while(m--) {scanf ("%d%d",&k,&h);    Addedge (K,H); }}BOOLBFs () {Q[bot=top=1]=t,d[t]=0, can[t]=false, tag[t]=++TAG;  while(bot<=top) {        intcur=q[bot++];  for(intI=first[cur]; i!=-1; I=Next[i]) {            if(c[i^1]>0&& tag[to[i]]!=TAG) {Tag[to[i]]=tag,q[++top]=To[i]; D[to[i]]=d[cur]+1, can[to[i]]=false; if(to[i]==s)return true; }        }    }    return false;}intDfsintCurintnum) {    if(cur==t)returnnum; inttmp=num,k;  for(intI=first[cur]; i!=-1; I=Next[i])if(c[i]>0&& d[to[i]]==d[cur]-1&& Tag[to[i]]==tag &&!Can[to[i]]) {k=Dfs (To[i],min (num,c[i)); if(k) num-=k,c[i]-=k,c[i^1]+=K; if(num==0) Break; }    if(num) can[cur]=true; returntmp-num;}BOOLCheckintx) {     for(intI=0; i<=boder; i++) c[i]=1;  for(inti=boder+1; i<=edge; i++) c[i]=x;  for(ans=0; BFS (); ) ans+=DFS (S,inf); returnans>=House ;}intMain () {scanf ("%d",&T);  while(t--) {_input (); intL=1, r=N,mid;  while(l<r) {Mid= (l+r) >>1; if(Check (mid)) r=mid; ElseL=mid+1; } printf ("%d\n", L); }    return 0;}

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.