Guest User

Untitled

a guest
Mar 13th, 2019
1,894
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. //#pragma comment(linker, ”/STACK:36777216“)
  3.  
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. #define mp make_pair
  8. #define pb push_back
  9. #define x first
  10. #define y second
  11. #define all(a) a.begin(), a.end()
  12. #define db long double
  13.  
  14. int n, m;
  15. vector<int> a, was;
  16. vector<vector<int> > g;
  17.  
  18. int main(){
  19. //freopen("input.txt", "r", stdin);
  20. //freopen("output.txt", "w", stdout);
  21. ios_base::sync_with_stdio(0); cin.tie(0);
  22. cin >> n >> m;
  23. a.resize(n);
  24. g.resize(n);
  25. was.resize(n);
  26. for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  27. for (int i = 0; i < m; i++){
  28. int w1, w2;
  29. cin >> w1 >> w2;
  30. w1--; w2--;
  31. g[w1].pb(w2);
  32. }
  33.  
  34. reverse(all(a));
  35. int ans = 0;
  36.  
  37. for (int i = 0; i < n; i++) was[i] = 0;
  38. was[a[0]] = 1;
  39. int cnt = 1;
  40. for (int i = 1; i < n; i++){
  41. int cnt2 = 0;
  42. for (int to : g[a[i]]){
  43. if (was[to]) cnt2++;
  44. }
  45. if (cnt == cnt2){
  46. ans++;
  47. } else {
  48. was[a[i]] = 1;
  49. cnt++;
  50. }
  51. }
  52.  
  53. cout << ans;
  54. }
RAW Paste Data