问题一:是否存在一个最小代价路径切断方案,其中该道路被切断? 问题二:是否对任何一个最小代价路径切断方案,都有该道路被切断? 现在请你回答这两个问题。
最小割唯一性判定
jcvb:
在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号。显然有id[s]!=id[t](否则s到t有通路,能继续增广)。
①对于任意一条满流边(u,v),(u,v)能够出现在某个最小割集中,当且仅当id[u]!=id[v];
②对于任意一条满流边(u,v),(u,v)必定出现在最小割集中,当且仅当id[u]==id[s]且id[v]==id[t]。
①
<==将每个SCC缩成一个点,得到的新图就只含有满流边了。那么新图的任一s-t割都对应原图的某个最小割,从中任取一个把id[u]和id[v]割开的割即可证明。
②
<==:假设将(u,v)的边权增大,那么残余网络中会出现s->u->v->t的通路,从而能继续增广,于是最大流流量(也就是最小割容量)会增大。这即说明(u,v)是最小割集中必须出现的边。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # include <set> # include <cmath> # include <algorithm> using namespace std; # define lowbit(x) ((x)&(-x)) # define pi 3.1415926535 # define eps 1e-9 # define MOD 100000007 # define INF 1000000000 # define mem(a,b) memset(a,b,sizeof(a)) # define FOR(i,a,n) for(int i=a; i<=n; ++i) # define FO(i,a,n) for(int i=a; i<n; ++i) # define bug puts("H"); # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mp make_pair # define pb push_back typedef pair<int,int> PII; typedef vector<int> VI; # pragma comment(linker, "/STACK:1024000000,1024000000") typedef long long LL; int Scan() { int res=0, flag=0; char ch; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+(ch-'0'); return flag?-res:res; } void Out(int a) { if(a<0) {putchar('-'); a=-a;} if(a>=10) Out(a/10); putchar(a%10+'0'); } const int N=5005; //Code begin... struct Edge{int p, next, w;}edge[120005]; int head[N], cnt=2, s, t, vis[N]; queue<int>Q; int Low[N], DFN[N], Stack[N], Belong[N], Index, top, scc; bool Instack[N], ans[60005][2]; void add_edge(int u, int v, int w){ edge[cnt].p=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++; edge[cnt].p=u; edge[cnt].w=0; edge[cnt].next=head[v]; head[v]=cnt++; } int bfs(){ int i, v; mem(vis,-1); vis[s]=0; Q.push(s); while (!Q.empty()) { v=Q.front(); Q.pop(); for (i=head[v]; i; i=edge[i].next) { if (edge[i].w>0 && vis[edge[i].p]==-1) { vis[edge[i].p]=vis[v] + 1; Q.push(edge[i].p); } } } return vis[t]!=-1; } int dfs(int x, int low){ int i, a, temp=low; if (x==t) return low; for (i=head[x]; i; i=edge[i].next) { if (edge[i].w>0 && vis[edge[i].p]==vis[x]+1){ a=dfs(edge[i].p,min(edge[i].w,temp)); temp-=a; edge[i].w-=a; edge[i^1].w += a; if (temp==0) break; } } if (temp==low) vis[x]=-1; return low-temp; } void Tarjan(int u){ int v; Low[u]=DFN[u]=++Index; Stack[top++]=u; Instack[u]=true; for (int i=head[u]; i; i=edge[i].next) { if (edge[i].w==0) continue; v=edge[i].p; if (!DFN[v]) { Tarjan(v); if (Low[u]>Low[v]) Low[u]=Low[v]; } else if (Instack[v]&&Low[u]>DFN[v]) Low[u]=DFN[v]; } if (Low[u]==DFN[u]) { ++scc; do{v=Stack[--top]; Instack[v]=false; Belong[v]=scc;}while (v!=u); } } void solve(int n){ mem(DFN,0); mem(Instack,0); Index=scc=top=0; FOR(i,1,n) if (!DFN[i]) Tarjan(i); } int main () { int n, m, u, v, w, tmp, res=0; n=Scan(); m=Scan(); s=Scan(); t=Scan(); FOR(i,1,m) u=Scan(), v=Scan(), w=Scan(), add_edge(u,v,w); while (bfs()) while (tmp=dfs(s,INF)) res+=tmp; solve(n); for (int i=2; i<cnt; i+=2) { if (edge[i].w) {puts("0 0"); continue;} u=edge[i].p, v=edge[i^1].p; if (Belong[u]!=Belong[v]) ans[i/2][0]=1; if (Belong[v]==Belong[s]&&Belong[u]==Belong[t]) ans[i/2][1]=1; printf("%d %d ",ans[i/2][0],ans[i/2][1]); } return 0; }