Pagini recente » Cod sursa (job #1304658) | Cod sursa (job #621387) | Cod sursa (job #1538709) | Cod sursa (job #2602858) | Cod sursa (job #82604)
Cod sursa(job #82604)
program critice;
const
fin='critice.in';
fout='critice.out';
nmax=1010;
mmax=20020;
inf=maxlongint shr 1;
type
int=array[1..nmax] of integer;
lint=array[1..nmax] of longint;
tlint=^lint;
tinteger=^int;
mint=array[1..mmax] of integer;
mlint=array[1..mmax] of longint;
mtlint=^mlint;
mtinteger=^mint;
vbool=array[1..nmax] of boolean;
pbool=^vbool;
var
target,prev,start:mint;
capa,flow:mint;
last,pred,q:tinteger;
critic,used:pbool;
delta:mtlint;
pop,push,m,ii,cur,i,j,k,n,x,y,c,nedge:longint;
tflow:longint;
num:longint;
function abs(x:longint):longint;
begin
if x<0 then
abs:=-x
else
abs:=x;
end;
procedure insert(x,y,c:longint);
begin
inc(nedge);
start[nedge]:=x;target[nedge]:=y;
capa[nedge]:=c;
prev[nedge]:=last^[x];
last^[x]:=nedge;
inc(nedge);
start[nedge]:=y;target[nedge]:=x;
capa[nedge]:=c;
prev[nedge]:=last^[y];
last^[y]:=nedge;
end;
function op(n:integer):integer;
begin
if n and 1=1 then
op:=n+1
else
op:=n-1;
end;
begin
new(last);new(pred);new(q);new(delta);
new(critic);new(used);
assign(input,fin);
reset(input);
readln(n,m);
nedge:=0;
for i:=1 to m do
begin
readln(x,y,c);
insert(x,y,c);
end;
close(input);
assign(output,fout);
rewrite(output);
tflow:=0;
while true do
begin
pop:=1;push:=2;
q^[1]:=1;
fillchar(used^,sizeof(used^),false);
delta^[1]:=inf;
used^[1]:=true;
cur:=1;
while pop<push do
begin
x:=last^[q^[pop]];
while x>0 do
begin
if (abs(flow[x])<capa[x]) then
if (not(used^[target[x]])) then
begin
used^[target[x]]:=true;
q^[push]:=target[x];
inc(push);
pred^[target[x]]:=x;
delta^[target[x]]:=delta^[start[x]];
if delta^[target[x]]>capa[x]-flow[x] then
delta^[target[x]]:=capa[x]-flow[x];
if used^[n] then
break;
end;
x:=prev[x];
end;
inc(pop);
end;
if not(used^[n]) then
break;
cur:=n;
x:=delta^[n];
inc(tflow,delta^[n]);
repeat
x:=pred^[cur];
inc(flow[x],delta^[n]);
y:=op(x);
flow[y]:=flow[y]-delta^[n];
cur:=start[x];
until cur=1;
end;
fillchar(used^,sizeof(used^),false);
q^[1]:=1;pop:=1;push:=2;used^[1]:=true;
critic^[1]:=true;
while pop<push do
begin
cur:=q^[pop];
inc(pop);
x:=last^[cur];
while x>0 do
begin
if (abs(flow[x])<capa[x]) and (not(used^[target[x]])) then
begin
used^[target[x]]:=true;
q^[push]:=target[x];
inc(push);
critic^[target[x]]:=true;
end;
x:=prev[x];
end;
end;
fillchar(used^,sizeof(used^),false);
q^[1]:=n;pop:=1;push:=2;used^[n]:=true;
while pop<push do
begin
cur:=q^[pop];
inc(pop);
x:=last^[cur];
while x>0 do
begin
if (abs(flow[x])<capa[x]) and (not(used^[target[x]])) then
begin
used^[target[x]]:=true;
q^[push]:=target[x];
inc(push);
end;
x:=prev[x];
end;
end;
num:=0;
for i:=1 to nedge do
if (critic^[start[i]])and (used^[target[i]]) then
inc(num);
writeln(num);
for i:=1 to nedge do
if (critic^[start[i]])and (used^[target[i]]) then
writeln((i+1)shr 1);
close(output);
end.