题意:。。。。emm。。。就是一个最小割最大流,。,。。。用dinic跑一遍。。
然后让你输出割边,就是 u为能从起点到达的点, v为不能从起点到达的点
最后在残余路径中用dfs跑一遍 能到达的路标记一下
然后循环判断输出即可 还有不要忘了是正向路 所以循环时i+=2
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 100009
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int INF = 0x3f3f3f3f;
int head[maxn], d[maxn], cur[maxn], vis[maxn];
int n, m, s, t;
int cnt = ;
struct node{
int u, v, c, next;
}Node[maxn*]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u, int v, int c)
{
add_(u, v, c);
add_(v, u, c);
} bool bfs()
{
queue<int> Q;
mem(d,);
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[e.u] + ;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
return d[t] != ;
} int dfs(int u, int cap)
{
if(u == t || cap == )
return cap;
int ret = ;
for(int &i=cur[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] == d[e.u] + && e.c > )
{
int V = dfs(e.v, min(cap, e.c));
Node[i].c -= V;
Node[i^].c += V;
cap -= V;
ret += V;
if(cap == ) break;
}
}
return ret;
} int dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur, head, sizeof(head));
ans += dfs(s, INF);
}
return ans;
} void find(int u)
{
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(vis[e.v] || e.c == ) continue;
vis[e.v] = ;
find(e.v);
}
} int main()
{
while(~scanf("%d%d",&n,&m) && n+m)
{
mem(vis,);
mem(head,-);
cnt = ;
s = ; t = ;
for(int i=; i<m; i++)
{
int u, v, c;
scanf("%d%d%d",&u,&v,&c);
add(u, v, c);
} dinic();
vis[s] = ;
find(s); //寻找能从s到达的路
for(int i=; i<cnt; i+=)
if(vis[Node[i].u] && !vis[Node[i].v] || !vis[Node[i].u] && vis[Node[i].v]) // 如果一个能到达 另一个不能到达 则为割边 输出即可
cout<< Node[i].u << " " << Node[i].v <<endl;
cout<< endl;
} return ;
}