Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _USE_MATH_DEFINES
  3. #include <iostream>
  4. #include <string>
  5. #include <map>
  6. #include <set>
  7. #include <algorithm>
  8. #include <vector>
  9. #include <stdio.h>
  10. #include <cmath>
  11. #include <math.h>
  12. #include <math.h>
  13. #include <queue>
  14. #include <stack>
  15. #include <climits>
  16. #include <deque>
  17. #include <ctime>
  18. #include <iomanip>
  19. #include <bitset>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22. #include <fstream>
  23. using namespace std;
  24. typedef long long ll;
  25. typedef unsigned long long ull;
  26. typedef unsigned int ui;
  27. #define sor(n) n.begin(), n.end()
  28. #define rsor(n) n.rbegin(), n.rend()
  29. #define mp make_pair
  30. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  31. #define p(T) pair<T,T>
  32. #define precis(x) cout.precision(x), cout.setf(ios::fixed)
  33. #define SWS ios::sync_with_stdio(false)
  34. #define CT cin.tie(0), cout.tie(0)
  35.  
  36. vector<vector<int>>f;
  37. map<int, bool>ma;
  38.  
  39. int main() {
  40. SWS; CT;
  41. int n, m;
  42. cin >> n >> m;
  43.  
  44. f.resize(m + n + 2);
  45. for (int i = 0; i != m; ++i) {
  46. int u, v;
  47. cin >> u >> v;
  48.  
  49. f[v].push_back(u);
  50. }
  51.  
  52. for (int i = 0; i != n; ++i) {
  53. int a;
  54. cin >> a;
  55. if (i == 0 && f[a].size() == 0) {
  56. ma[a] = 1;
  57. continue;
  58. }
  59. else if (i == 0 && f[a].size() != 0) {
  60. cout << "NO";
  61. //system("pause");
  62. return 0;
  63. }
  64. if (f[a].size() == 0) {
  65. ma[a] = 1;
  66. continue;
  67. }
  68. for (auto v : f[a]) {
  69. if (!ma[v]) {
  70. cout << "NO";
  71. //system("pause");
  72. return 0;
  73. }
  74. }
  75. ma[a] = 1;
  76.  
  77. }
  78. cout << "YES";
  79. //system("pause");
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement