fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fi first
  5. #define se second
  6. #define pub push_back
  7. #define pob pop_back
  8. #define mpa make_pair
  9. #define endl '\n'
  10. #define BIT(i) ((1 << i))
  11. const int maxn = 1e5 + 10;
  12. int c, n, m;
  13. bool state[maxn];
  14. pair<int, int> a[maxn];
  15. int res[maxn];
  16. void solve()
  17. {
  18. for(int i=m; i>=1; i--)
  19. {
  20. bool ok = state[a[i].fi] & state[a[i].se];
  21. state[a[i].fi] = state[a[i].se] = ok;
  22. }
  23. if(c == 1)
  24. {
  25. for(int i=1; i<=n; i++) cout << state[i];
  26. }
  27. else
  28. {
  29. for(int i=1; i<=n; i++)
  30. {
  31. if(state[i] == 1) res[i] = i;
  32. else res[i] = -1;
  33. }
  34. for(int i=1; i<=m; i++)
  35. {
  36. int u = a[i].fi;
  37. int v = a[i].se;
  38. if(res[u] == 1e9 || res[v] == 1e9)
  39. {
  40. res[u] = res[v] = 1e9;
  41. }
  42. else if(res[u] == -1)
  43. {
  44. res[u] = res[v];
  45. }
  46. else if(res[v] == -1)
  47. {
  48. res[v] = res[u];
  49. }
  50. else if(res[v] != res[u]) res[v] = res[u] = 1e9;
  51. }
  52. memset(state, 1, sizeof state);
  53. for(int i=1; i<=n; i++)
  54. {
  55. if(res[i] != -1 && res[i] != 1e9) state[res[i]] = 0;
  56. }
  57. for(int i=1; i<=n; i++) cout << state[i];
  58. }
  59.  
  60. }
  61. int main()
  62. {
  63. ios_base::sync_with_stdio(false);
  64. cin.tie(0);
  65. cout.tie(0);
  66. #define code code
  67. // freopen("code.INP","r",stdin);
  68. // freopen("code.OUT","w",stdout);
  69. cin >> c >> n >> m;
  70. for(int i=1; i<=n; i++) cin >> state[i];
  71. for(int i=1; i<=m; i++) cin >> a[i].fi >> a[i].se;
  72. solve();
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty