Advertisement
kolbka_

Untitled

Feb 2nd, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10.  
  11. #include "optimization.h"
  12. #include <unordered_map>
  13.  
  14. #include <cassert>
  15. #include <cstdio>
  16. #include <algorithm>
  17.  
  18.  
  19. using namespace std;
  20. int n, m;
  21. vector<bool> mark;
  22. vector<int> comp;
  23. vector<vector<int>> graph;
  24. vector<int> order;
  25. int cc = 0;
  26.  
  27. void dfs1(int v) {
  28. mark[v] = true;
  29. for (auto u: graph[v]) {
  30. if (!mark[u]) dfs1(u);
  31. }
  32. order.push_back(v);
  33. }
  34.  
  35. void dfs2(int v, int cc) {
  36. comp[v] = cc;
  37. for (auto u: graph[v]) {
  38. if (comp[v] == -1) {
  39. dfs2(u, cc);
  40. }
  41. }
  42. }
  43.  
  44. int main() {
  45. cin >> n >> m;
  46. // vector<bool> x((n+1)*2, 0);
  47. graph.resize((n + 1) * 2);
  48. for (int i = 0; i < m; i++) {
  49. int a, a_val, b, b_val;
  50. cin >> a >> a_val >> b >> b_val;
  51. // if (a_val == 1) {
  52. // graph[a * 2].push_back(b_val ? );
  53. // } else {
  54. // graph[a * 2 + 1].push_back(b);
  55. // }
  56. // if (b_val == 1) {
  57. // graph[b * 2].push_back(a);
  58. // } else {
  59. // graph[b * 2 + 1].push_back(a);
  60. // }
  61. // graph[a_val == 1 ? a*2 : a * 2 + 1].push_back(b_val ? b * 2 + 1 : 2 *b);
  62. // graph[b_val == 1 ? b*2 : b * 2 + 1].push_back(a_val ? a * 2 + 1 : 2 *a);
  63. graph[2 * a + 1 - a_val].push_back(2 * b + b_val);
  64. graph[2 * b + 1 - b_val].push_back(2 * a + a_val);
  65. }
  66.  
  67. mark.resize(2 * (n + 1), false);
  68. for (int i = 1; i <= 2 * n; ++i) {
  69. if (!mark[i]) dfs1(i);
  70. }
  71.  
  72. comp.resize(2 * (n + 1), -1);
  73. reverse(order.begin(), order.end());
  74. for (auto v: order) {
  75. if (comp[v] == -1) {
  76. dfs2(v, ++cc);
  77. }
  78. }
  79.  
  80. for (int i = 1; i <= 2*n; i+=2) {
  81. cout << (comp[i + 1] > comp[i]);
  82. }
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement