#include #include #include #include #include #include #include #include #include using namespace std; struct edge { int a,b,c; }; int n,m; int V,R; vector< pair > Graph[10011]; edge edges[100011]; int w[10011]; int d[10011]; vector< pair > RGraph[10011]; int SubtreeSize[10011]; int SubSize[10011]; int RemBest[10011]; vector SGraph[10011]; bool PathExists[10011][10011]; int TIME_LIMIT=4*CLOCKS_PER_SEC+(2*CLOCKS_PER_SEC)/3; bool TimeIsOK() { return clock() > EdgeList; vector< pair< int,pair > > PotentialEdgeList; int saturation[10011]; int CurValue; void Clear() { memset(TFO1,false,sizeof(TFO1)); memset(TFO2,false,sizeof(TFO2)); memset(saturation,0,sizeof(saturation)); EdgeList.clear(); PotentialEdgeList.clear(); memset(TheCabin,-1,sizeof(TheCabin)); CurValue=0; return; } bool TreeCase; void SimDFS(int v1,int v2,int comefrom) { int i; int r2; pair r1; priority_queue< pair > List1; vector List2; TheCabin[v1]=v2; TFO1[v1]=true; TFO2[v2]=true; if (saturation[v1]==d[v1]) return; if (TreeCase) { for (i=0;i > List1; vector List2; TheCabin[v1]=v2; TFO1[v1]=true; TFO2[v2]=true; if (saturation[v1]==d[v1]) return; if (TreeCase) { for (i=0;i > r1; pair< int,int > r2; priority_queue< pair< int, pair > > List1; priority_queue< pair< int,int > > List2; TheCabin[v1]=v2; TFO1[v1]=true; TFO2[v2]=true; for (i=0;i , int > a, pair< pair , int > b) { return a.second>b.second; } int Compute(int ver,int dad) { int i; vector< pair< pair , int > > List; int sum=0; int v; int toff; if (dad==0) toff=0; else toff=1; SubtreeSize[ver]=1; for (i=0;id[ver]-toff) { List.pop_back(); } for (i=0;i > BestEdges; vector< pair > Accommodation; int biggest=0; int reduced=0; void MaximumSubgraph(bool z) { int V1,V2; int i; V1=rand()%n+1; V2=rand()%V+1; if (RemBest[V1]!=-1) { if (RemBest[V1]biggest) biggest=RemBest[V1]; } TreeCase=z; Clear(); SimDFS(V1,V2,0); GetLeftOvers(); if (BestValuebiggest) biggest=RemBest[V1]; } TreeCase=z; Clear(); SimDFSMax(V1,V2,0); GetLeftOvers(); if (BestValuebiggest) biggest=RemBest[V1]; SubSize[V2]=GetSizes(V2,0); TreeCase=true; Clear(); SpecDFSTree(V1,V2); GetLeftOvers(); if (BestValue