• Source
    1. #include <iostream>
    2. #include <vector>
    3. using namespace std;
    4.  
    5. int N, M, K;
    6. vector <int> person;
    7. vector <int> road[1003];
    8. int count[1003];
    9. void read ()
    10. {
    11. cin>>K>>N>>M;
    12. int ps;
    13. for (int i=1; i<=K; i++)
    14. {
    15. cin>>ps;
    16. person.push_back(ps);
    17. }
    18. for (int i=1; i<=M; i++)
    19. {
    20. int A, B;
    21. cin>>A>>B;
    22. road[A].push_back(B);
    23. }
    24. for (int i=1; i<=N; i++)
    25. {
    26. count[1003];
    27. }
    28. }
    29.  
    30. int check[1003];
    31. void init ()
    32. {
    33. for (int i=1; i<=N; i++)
    34. {
    35. check[i]=0;
    36. }
    37. }
    38.  
    39. void loang (int u)
    40. {
    41. for (int i=0; i<road[u].size(); i++)
    42. {
    43. int v=road[u][i];
    44. if (check[v]==0)
    45. {
    46. check[v]=1;
    47. count[v]++;
    48. loang (v);
    49. }
    50. }
    51. }
    52.  
    53. int main ()
    54. {
    55. read ();
    56. for (int i=0; i<person.size(); i++)
    57. {
    58. init ();
    59. check[person[i]]=1;
    60. count[person[i]]++;
    61. loang (person[i]);
    62. }
    63. int answer=0;
    64. for (int i=1; i<=N; i++)
    65. {
    66. if (count[i]==K) answer++;
    67. }
    68. cout<<answer;
    69. return 0;
    70. }