#include<bits/stdc++.h>
using namespace std;
const int INF = 213132323;
int head[500],cur[500],dis[600];
int n,m,x,cnt = 0;
struct P{
int v,w,nxt;}e[5000];
inline int read(){
int ans = 0;
char r = getchar();
while(r<'0'||r>'9') r=getchar();
while(r>='0'&&r<='9') {ans=ans*10+r-'0';r=getchar();}
return ans;
}
void add(int u,int v,int w)
{
e[cnt].v=v;
e[cnt].w=w;
e[cnt].nxt =head[u];
head[u]=cnt;
cnt++;
}
bool bfs()
{
memset(dis,-1,sizeof(dis));
dis[1] = 0;
queue<int>q;
q.push(1);
while(!q.empty())
{
int r = q.front();
q.pop();
for(int i = head[r];i!=-1;i=e[i].nxt)
{
int v = e[i].v;
if(dis[v]==-1 && e[i].w>0)//e[i].w写成e[i].v
{
dis[v]=dis[r]+1;
q.push(v);//?>?????????????
}
}
}
return dis[n]!=-1;
}
int dfs(int u,int num)
{
if(u==n) return num;
int delta = num;
for(int i = cur[u];i!=-1;i=e[i].nxt)
{
cur[u]=e[i].nxt;
int v = e[i].v;
if(dis[v]==dis[u]+1 && e[i].w>0)
{
int d = dfs(v,min(delta,e[i].w));
e[i].w-=d;
e[i^1].w+=d;
delta-=d;
if(delta==0) break;
}
}
return num-delta;
}
int dini()
{ int ans = 0;
while(bfs()){
for(int i = 1;i <= n;i++)cur[i]=head[i];
ans +=dfs(1,INF);
}
return ans;
}
int main(){
memset(head,-1,sizeof(head));
n = read();
m = read();
x = read();
for(int i = 1;i <= m;i++)
{
int a,b,c;
a=read();
b=read();
c=read();
add(a,b,c);
add(b,a,0);
}
int a = dini();
if(a==0) cout<<"Orz Ni Jinan Saint Cow!"<<endl;
else cout<<a<<" "<<(x-1)/a+1<<endl;
return 0;
}
洛谷p1343(网络流模板)
最新推荐文章于 2021-07-20 11:28:53 发布