Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#pragma comment(linker, ”/STACK:36777216“)
- using namespace std;
- typedef long long ll;
- #define mp make_pair
- #define pb push_back
- #define x first
- #define y second
- #define all(a) a.begin(), a.end()
- #define db long double
- int n, m;
- vector<int> a, was;
- vector<vector<int> > g;
- int main(){
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(0); cin.tie(0);
- cin >> n >> m;
- a.resize(n);
- g.resize(n);
- was.resize(n);
- for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
- for (int i = 0; i < m; i++){
- int w1, w2;
- cin >> w1 >> w2;
- w1--; w2--;
- g[w1].pb(w2);
- }
- reverse(all(a));
- int ans = 0;
- for (int i = 0; i < n; i++) was[i] = 0;
- was[a[0]] = 1;
- int cnt = 1;
- for (int i = 1; i < n; i++){
- int cnt2 = 0;
- for (int to : g[a[i]]){
- if (was[to]) cnt2++;
- }
- if (cnt == cnt2){
- ans++;
- } else {
- was[a[i]] = 1;
- cnt++;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement