Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- #include <iomanip>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define sor(n) n.begin(), n.end()
- #define rsor(n) n.rbegin(), n.rend()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define precis(x) cout.precision(x), cout.setf(ios::fixed)
- #define SWS ios::sync_with_stdio(false)
- #define CT cin.tie(0), cout.tie(0)
- vector<vector<int>>f;
- map<int, bool>ma;
- int main() {
- SWS; CT;
- int n, m;
- cin >> n >> m;
- f.resize(m + n + 2);
- for (int i = 0; i != m; ++i) {
- int u, v;
- cin >> u >> v;
- f[v].push_back(u);
- }
- for (int i = 0; i != n; ++i) {
- int a;
- cin >> a;
- if (i == 0 && f[a].size() == 0) {
- ma[a] = 1;
- continue;
- }
- else if (i == 0 && f[a].size() != 0) {
- cout << "NO";
- //system("pause");
- return 0;
- }
- if (f[a].size() == 0) {
- ma[a] = 1;
- continue;
- }
- for (auto v : f[a]) {
- if (!ma[v]) {
- cout << "NO";
- //system("pause");
- return 0;
- }
- }
- ma[a] = 1;
- }
- cout << "YES";
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement