Pagini recente » Cod sursa (job #3159196) | Cod sursa (job #832991) | Cod sursa (job #2437754) | Cod sursa (job #3229028) | Cod sursa (job #2824324)
#include <bits/stdc++.h>
using namespace std;
inline void Open(const string Name) {
#ifndef ONLINE_JUDGE
(void)!freopen((Name + ".in").c_str(), "r", stdin);
(void)!freopen((Name + ".out").c_str(), "w", stdout);
#endif
}
const int INF = 2e9;
vector <int> Gr[1001];
vector <pair <int, int>> Edges;
vector <int> ans;
queue <int> q;
bitset <1001> b1, b2;
int flow[1001][1001], capacity[1001][1001];
int depth[1001];
int N, M, x, y, z;
int dfs(int nod, int fflow) {
if(nod == N)
return fflow;
for(int &v : Gr[nod]) {
if(depth[v] == depth[nod] + 1 && capacity[nod][v] - flow[nod][v] > 0) {
int tmpFlow = dfs(v, min(fflow, capacity[nod][v] - flow[nod][v]));
if(tmpFlow > 0) {
flow[nod][v] += tmpFlow;
flow[v][nod] -= tmpFlow;
return tmpFlow;
}
}
}
depth[nod] = 0;
return 0;
}
bool bfs() {
memset(depth, 0, sizeof(depth));
depth[1] = 1;
q.emplace(1);
while(!q.empty()) {
int nod = q.front();
q.pop();
for(int &v : Gr[nod])
if(!depth[v] && capacity[nod][v] > flow[nod][v]) {
depth[v] = depth[nod] + 1;
q.emplace(v);
}
}
return(depth[N] != 0);
}
void dfs1(int nod) {
b1[nod] = 1;
for(int to : Gr[nod]) {
if(!b1[to] && capacity[nod][to] > flow[nod][to])
dfs1(to);
}
}
void dfs2(int nod) {
b2[nod] = 1;
for(int to : Gr[nod]) {
if(!b2[to] && capacity[to][nod] > flow[to][nod])
dfs2(to);
}
}
void solve() {
cin >> N >> M;
for(int i = 1;i <= M;i++) {
cin >> x >> y >> z;
Gr[x].emplace_back(y);
Gr[y].emplace_back(x);
Edges.emplace_back(x, y);
capacity[x][y] = capacity[y][x] = z;
}
int maxFlow = 0;
while(bfs()) {
int tmpFlow = 0;
do {
tmpFlow = dfs(1, INF);
maxFlow += tmpFlow;
}while(tmpFlow > 0);
}
dfs1(1), dfs2(N);
for(int i = 0;i < M;i++){
x = Edges[i].first, y = Edges[i].second;
if((b1[x] && b2[y]) || (b2[x] && b1[y]))
ans.emplace_back(i + 1);
}
cout << ans.size() << "\n";
for(int x : ans)
cout << x << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
Open("critice");
int T = 1;
for(;T;T--) {
solve();
}
return 0;
}