1 type edge=record 2 nt,u,v:longint; 3 end; 4 const maxn=100008; 5 maxm=200008; 6 var eg:array[0..maxm*2] of edge; 7 lt:array[0..maxn] of longint; 8 dfn,low,stack,cl:array[0..maxn] of longint; 9 i,j,n,m,u,v,sum,num,k:longint; 10 tmp,now:longint; 11 procedure add(u,v:longint); 12 begin 13 inc(sum); 14 eg[sum].u:=u; 15 eg[sum].v:=v; 16 eg[sum].nt:=lt[u]; 17 lt[u]:=sum; 18 end; 19 function min(a,b:longint):longint; 20 begin 21 if a<b then exit(a) else exit(b); 22 end; 23 procedure dfs(u,fa:longint); 24 var v,i:longint; 25 begin 26 inc(tmp); dfn[u]:=tmp; low[u]:=tmp; 27 inc(now); stack[now]:=u; 28 i:=lt[u]; 29 while i<>-1 do 30 begin 31 v:=eg[i].v; 32 if v<>fa then 33 if dfn[v]=0 then 34 begin 35 dfs(v,u); 36 low[u]:=min(low[u],low[v]); 37 end 38 else low[u]:=min(low[u],dfn[v]); 39 i:=eg[i].nt; 40 end; 41 if dfn[u]=low[u] then 42 begin 43 inc(num); 44 while true do 45 begin 46 v:=stack[now]; 47 cl[v]:=num; 48 dec(now); 49 if u=v then break; 50 end; 51 end; 52 end; 53 begin 54 for i:=1 to maxn do lt[i]:=-1; 55 readln(n,m); 56 sum:=-1; 57 for i:=1 to m do 58 begin 59 readln(u,v); 60 add(u,v); 61 add(v,u); 62 end; 63 for i:=1 to n do 64 if dfn[i]=0 then 65 dfs(i,0); 66 for i:=1 to sum do 67 if odd(i) then 68 begin 69 if cl[eg[i].u]<>cl[eg[i].v] then inc(k); 70 end; 71 writeln(k); 72 //for i:=1 to n do write(cl[i],‘ ‘); 73 end.
时间: 2024-10-16 09:50:20