fork download
  1. const
  2. fi='stable.inp';
  3. fo='stable.out';
  4. maxn=10000;
  5. maxm=50000;
  6. var
  7. link,head,ke : array[1..maxm] of longint;
  8. i,j,n,m,st,ans,s,dau,cuoi,u,v : longint;
  9. q,bac : array[1..maxn] of longint;
  10. ok : array[1..maxn] of boolean;
  11. a : array[1..maxn,1..maxn] of boolean;
  12. procedure push(x : longint);
  13. begin
  14. inc(cuoi);
  15. q[cuoi] := x;
  16. end;
  17. procedure add(i,u,v : longint);
  18. begin
  19. link[i] := head[u];
  20. head[u] := i;
  21. ke[i] := v;
  22. end;
  23. begin
  24. // assign(input,fi);reset(input);
  25. // assign(output,fo);rewrite(output);
  26. read(n,m,s);
  27. for i := 1 to m do
  28. begin
  29. read(u,v);
  30. if a[u,v] = false then
  31. add(i,u,v);
  32. a[u,v] := true;
  33. end;
  34. dau := 1; cuoi := 0;
  35. push(s);
  36. bac[s] := 1;
  37. while (dau <= cuoi) do
  38. begin
  39. u := q[dau];
  40. inc(dau);
  41. i := head[u];
  42. while i <> 0 do
  43. begin
  44. v := ke[i];
  45. if bac[v] = 0 then
  46. begin
  47. if ok[u] then ok[v] := true;
  48. bac[v] := bac[u] + 1;
  49. push(v);
  50. end
  51. else
  52. if bac[v] = bac[u] + 1 then
  53. begin
  54. ok[v] := true;
  55. end;
  56. i := link[i];
  57. end;
  58. end;
  59. for i := 1 to n do
  60. if ok[i] then inc(ans);
  61. writeln(ans);
  62. // close(input);close(output);
  63. end.
  64.  
Success #stdin #stdout 0s 98688KB
stdin
Standard input is empty
stdout
0