#include #include #include #include #include using namespace std; typedef pair Coords; int main() { int numHunt, numGroov; cin >> numHunt >> numGroov; unordered_map> grooves; vector yMax(numHunt+1, -1); for (int i = 0; i < numGroov; ++i) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; //Coords c1(x1, y1); //Coords c2(x2, y2); if (grooves.count(y1) == 0) grooves[y1] = unordered_map(); grooves[y1][x1] = x2; grooves[y1][x2] = x1; //grooves[c1] = c2; //grooves[c2] = c1; yMax[x1] = max(yMax[x1], y1); yMax[x2] = max(yMax[x2], y1); } //for (int i = 0; i < yMax.size(); ++i) //cout << "ymax for " << i << " is " << yMax[i] << endl; //cout << "numhunt " << numHunt << endl; for (int i = 1; i <= numHunt; ++i) { int hx = i; int hy = 0; while (hy <= yMax[hx]) { hy++; auto row = grooves.find(hy); if (row == grooves.end()) continue; auto col = row->second.find(hx); if (col != row->second.end()) { hx = col->second; } } cout << hx << endl; } return 0; }