#include #include using namespace std; using point = pair; struct Point { size_t x; size_t y; Point() : x(0), y(0) {} Point(size_t x, size_t y) : x(x), y(y) {} friend bool operator<(const Point &a, const Point &b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } }; int main() { size_t hunters, grooves; cin >> hunters >> grooves; map transport = map(); for (size_t g = 0; g < grooves; g++) { size_t x, y, ex, ey; cin >> x >> y >> ex >> ey; Point start = Point(x, y); Point end = Point(ex, ey); transport[start] = end; transport[end] = start; } for (size_t h = 1; h <= hunters; h++) { Point pos = {h, 0}; while (true) { auto it = transport.lower_bound(pos); if (it == transport.end()) { // cout << "end: " << it->first.x << " " << it->first.y << endl; // cout << "end res: " << it->second.x << " " << it->second.y << endl; break; } // cout << "current: " << pos.x << " " << pos.y << endl; // cout << it->first.x << " " << it->first.y << endl; if (it->first.x != pos.x || it->first.y < pos.y) break; pos = it->second; pos.y++; } cout << pos.x << endl; } return 0; }