Advertisement
kolbka_

Untitled

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