You are not logged in. Please login at www.codechef.com to post your questions!

×

SPOJ Total Flow WA!!!

Hey guys i am getting WA!!! coming plzz help me up!! i have used for_fulkserson algo here..

include<iostream>

include<list>

include<vector>

include<queue>

using namespace std; list<int> l[200]; list<int> v; int cost[200][200]; int rgraph[200][200]; int max1=10000; int parent[800]={0}; int max_flow=0;

bool bfs() { int g='A'; v.push_back(g); int visited[800]={0}; list<int>::iterator it; parent['A']=-1; //visited['A']=1; while(!v.empty()) { int u=v.front(); v.pop_front(); visited[u]=1; // cout<<"u valus is "<<u<<endl; for(it="l[u].begin();it!=l[u].end()&amp;&amp;rgraph[u][*it]">0&&visited[it]==0;it++) { // cout<<"rgraph valus is "<<u<<" "<<it<<" "<<rgraph[u][*it]<<endl;

        v.push_back(*it);
        parent[*it]=u;



    }

}if(visited['Z']==1)return true;
else
return false;

}

int ford() { int i,j,k,u;

while(bfs()) { int min=10000; //cout<<"hey"; for(u='Z';u!='A';u=parent[u]) {if(min>rgraph[parent[u]][u])min=rgraph[parent[u]][u];} // cout<<"min value is "<<min<<endl; for(u='Z';u!='A';u=parent[u]) { rgraph[parent[u]][u]-=min; rgraph[u][parent[u]]+=min; }

max_flow+=min;

}

}

int main() { int n,a,b,c,i,j,k;

cin>>n;
char ch1,ch2;
for(i=1;i<=n;i++)
{
    cin>>ch1;
    cin>>ch2;
    cin>>c;
    a=ch1;
    b=ch2;
    l[a].push_back(b);
    cost[a][b]=c;
    rgraph[a][b]=c;
}
ford();

cout<<max_flow<<endl;

// system("pause");
}

asked 28 Sep '13, 10:51

wonder's gravatar image

2★wonder
361183769
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,070

question asked: 28 Sep '13, 10:51

question was seen: 1,989 times

last updated: 28 Sep '13, 10:51