fork download
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define all(v) v.begin() , v.end()
  5. #define sz(v) int(v.size())
  6. #define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10. typedef pair<int , int> ii;
  11. typedef pair<long long , int> lli;
  12.  
  13. const int maxN = int(2e5)+7;
  14.  
  15. int n , m , a[maxN];
  16. vector<int> adj[maxN];
  17. vector<int> topo;
  18. bool vis[maxN];
  19. int g[maxN];
  20.  
  21. void dfs_topo(int u){
  22. vis[u] = 1;
  23. for (int v : adj[u]){
  24. if (vis[v] == 0){
  25. dfs_topo(v);
  26. }
  27. }
  28. topo.push_back(u);
  29. }
  30.  
  31. void solve(){
  32. cin >> n >> m;
  33. for (int i = 1 ; i <= m ; i++){
  34. int u , v;
  35. cin >> u >> v;
  36. adj[u].push_back(v);
  37. }
  38. for (int i = 1 ; i <= n ; i++) cin >> a[i];
  39. for (int i = 1 ; i <= n ; i++){
  40. if (vis[i] == 0) dfs_topo(i);
  41. }
  42. for (int u : topo){
  43. vector<int> val;
  44. for (int v : adj[u]) val.push_back(g[v]);
  45. unq(val);
  46. if (val.empty() == 0){
  47. if (val[0] > 0) g[u] = 0;
  48. else{
  49. g[u] = val.back() + 1;
  50. for (int i = 1 ; i < sz(val) ; i++){
  51. if (val[i - 1] + 1 < val[i]) g[u] = min(g[u] , val[i - 1] + 1);
  52. }
  53. }
  54. }
  55. }
  56. int x = 0;
  57. for (int i = 1 ; i <= n ; i++) if (a[i]&1) x ^= g[i];
  58. if (x) cout << "YES\n"; else cout << "NO\n";
  59. }
  60.  
  61. #define name "A"
  62.  
  63. int main(){
  64. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  65. if (fopen(name".INP" , "r")){
  66. freopen(name".INP" , "r" , stdin);
  67. freopen(name".OUT" , "w" , stdout);
  68. }
  69. int t = 1; //cin >> t;
  70. while (t--) solve();
  71. return 0;
  72. }
  73.  
  74.  
Success #stdin #stdout 0.01s 8352KB
stdin
Standard input is empty
stdout
NO