No title

Anonymous Coward 2018-03-08 02:55:09.24667 UTC

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<pii> vpii;
typedef tuple<int, int, int> iii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=600;
const ll INFTY=1e18;
vi adj[N];
int S, T, v[N];
ll c[N][N];

ll dfs(int i, ll f) {
    v[i]=1;
    if(i==T) return f;
    for(int j:adj[i]) if(c[i][j] && !v[j]) {
        ll rf=dfs(j, min(c[i][j], f));
        if(rf) {
            c[i][j]-=rf;
            c[j][i]+=rf;
            return rf;
        }
    }
    return 0;
}

int main() {
    int n, m, i, j, w;
    scanf("%d%d%d%d", &n, &m, &S, &T);
    while(m--) {
        scanf("%d%d%d", &i, &j, &w);
        adj[i].pb(j);
        adj[j].pb(i);
        c[i][j]+=w;
    }
    do {
        for(i=0; i<n; i++) v[i]=0;
    } while(dfs(S, INFTY));
    for(i=j=0; i<n; i++) j+=v[i];
    printf("%d\n", j);
    for(i=0; i<n; i++) if(v[i])
        printf("%d\n", i);
    return 0;
}