fork download
  1. {$M 4000000000}
  2. const maxn = 2000;
  3. maxm = 5000;
  4. fi = '';
  5. fo = '';
  6. var m,n,t:word;
  7. a: array[1..maxn,0..maxm] of word;
  8. visit: array[1..maxn] of boolean;
  9. procedure enter;
  10. var i,j,u,v:word;
  11. begin
  12. assign(input,fi);
  13. reset(input);
  14. readln(n,m);
  15. for i:=1 to n do
  16. begin
  17. a[i,0]:=0;
  18. visit[i]:=false;
  19. end;
  20. for i:=1 to m do
  21. begin
  22. readln(u,v);
  23. inc(a[u,0]);
  24. a[u,a[u,0]]:=v;
  25. inc(a[v,0]);
  26. a[v,a[v,0]]:=u;
  27. end;
  28. end;
  29. procedure dfs(i:word);
  30. var j:word;
  31. begin
  32. visit[i]:=true;
  33. for j:=1 to a[i,0] do
  34. if not visit[a[i,j]] then dfs(a[i,j]);
  35. end;
  36. procedure solve;
  37. var i:word;
  38. begin
  39. assign(output,fo);
  40. rewrite(output);
  41. t:=0;
  42. for i:=1 to n do
  43. if not visit[i] then
  44. begin
  45. inc(t);
  46. dfs(i);
  47. end;
  48. writeln(m-n+t);
  49. close(output);
  50. end;
  51. begin
  52. enter;
  53. solve;
  54. end.
Success #stdin #stdout 0s 19816KB
stdin
Standard input is empty
stdout
0