Advertisement
kolbka_

Untitled

Feb 2nd, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 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<vector<int>> graph2;
  25. vector<int> order;
  26. int cc = 0;
  27.  
  28. void dfs1(int v) {
  29. mark[v] = true;
  30. for (auto u: graph[v]) {
  31. if (!mark[u]) dfs1(u);
  32. }
  33. order.push_back(v);
  34. }
  35.  
  36. void dfs2(int v, int cc) {
  37. comp[v] = cc;
  38. for (auto u: graph2[v]) {
  39. if (comp[u] == -1) {
  40. dfs2(u, cc);
  41. }
  42. }
  43. }
  44.  
  45. int main() {
  46. std::ios_base::sync_with_stdio(0);
  47. cin.tie(0);
  48. cout.tie(0);
  49. while(cin >> n >> m){
  50.  
  51.  
  52. // vector<bool> x((n+1)*2, 0);
  53. graph.assign(n * 2, vector<int>());
  54. graph2.assign(n * 2, vector<int>());
  55. for (int i = 0; i < m; i++) {
  56. int a, a_val, b, b_val;
  57. cin >> a >> a_val >> b >> b_val;
  58.  
  59. graph[2 * a + 1 - a_val].push_back(2 * b + b_val);
  60. graph[2 * b + 1 - b_val].push_back(2 * a + a_val);
  61. graph2[2 * b + b_val].push_back(2 * a + 1 - a_val);
  62. graph2[2 * a + a_val].push_back(2 * b + 1 - b_val);
  63. }
  64.  
  65. mark.assign(2 * (n), false);
  66. for (int i = 0; i < 2 * n; i+=1) {
  67. if (!mark[i]) dfs1(i);
  68. }
  69. comp.assign(2 * (n), -1);
  70. reverse(order.begin(), order.end());
  71. for (auto v: order) {
  72. if (comp[v] == -1) {
  73. dfs2(v, ++cc);
  74. }
  75. }
  76.  
  77. for (int i = 0; i < 2*n; i+=2) {
  78. cout << (comp[i + 1] > comp[i]);
  79. }
  80. cout << '\n';
  81. }}
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement