1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Autor: Nicolas Wochnik
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

#define STUPID 0
#define INTELLIGENT 1
#define UNKNOWN 2

int number_of_soldiers;

std::vector<std::vector<char>> possibilities;

std::vector<char> answer;

void parse_move(int from, int to) {
  size_t possib_count = possibilities.size();

  for (size_t i = 0; i < possib_count; ++i) {
    auto &from_state = possibilities[i][from], &to_state = possibilities[i][to];

    if (from_state == UNKNOWN && to_state == UNKNOWN) {
      possibilities.push_back(possibilities[i]);
      auto &new_possib = possibilities.back();

      from_state = STUPID;
      to_state = STUPID;

      new_possib[from] = INTELLIGENT;
      new_possib[to] = INTELLIGENT;
    }

    if (from_state == UNKNOWN && to_state == STUPID ||
        from_state == INTELLIGENT && to_state == STUPID ||
        from_state == INTELLIGENT && to_state == UNKNOWN) {
      std::swap(from_state, to_state);
    }
  }
}

void apply_full(size_t size) {
  for (size_t i = 1; i <= size; ++i) {
    answer[i - 1] += size - i + 1;
    answer[i - 1] %= 2;
  }
}

void apply_size(size_t size, size_t left, size_t right) {
  int ways = 0;

  for (int i = size; i <= size + left + right; ++i) {
    if (i <= size + std::min(left, right)) {
      ways++;
    } else if (i > size + std::max(left, right)) {
      ways--;
    }

    answer[i - 1] += ways;
    answer[i - 1] %= 2;
  }

  return;
}

void parse_possibility(size_t i) {
  const auto &poss = possibilities[i];

  auto first_intelligent = std::find(poss.begin(), poss.end(), INTELLIGENT);
  auto last_intelligent = std::find(poss.rbegin(), poss.rend(), INTELLIGENT);

  if (first_intelligent == poss.end() && last_intelligent == poss.rend()) {
    size_t unknown_interval = 0;

    for (size_t i = 0; i < poss.size(); ++i) {
      if (poss[i] == UNKNOWN) {
        unknown_interval++;
      } else {
        apply_full(unknown_interval);
        unknown_interval = 0;
      }
    }

    apply_full(unknown_interval);

    return;
  }

  size_t size = 1, left = 0, right = 0;

  for (auto ptr = first_intelligent; ptr != last_intelligent.base() - 1;
       ++ptr) {
    if (*ptr == STUPID) {
      return; // no intelligent life here
    }

    size++;
  }

  for (auto ptr = first_intelligent; ptr-- != poss.begin();) {
    if (*ptr == STUPID) {
      break;
    }

    left++;
  }

  for (auto ptr = last_intelligent; ptr-- != poss.rbegin();) {
    if (*ptr == STUPID) {
      break;
    }

    right++;
  }

  apply_size(size, left, right);
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  size_t moves_count;
  std::cin >> number_of_soldiers >> moves_count;

  possibilities = {};
  possibilities.push_back(std::vector<char>(number_of_soldiers, UNKNOWN));

  for (size_t i = 0; i < moves_count; ++i) {
    int from, to;
    std::cin >> from >> to;
    from--, to--;

    parse_move(from, to);
  }

  answer = std::vector<char>(number_of_soldiers, 0);

  for (size_t i = 0; i < possibilities.size(); ++i) {
    parse_possibility(i);
  }

  for (auto x : answer) {
    std::cout << (x % 2) << " ";
  }
  std::cout << "\n";

  return 0;
}