| 123456789101112131415161718192021222324252627282930 |
- #include <iostream>
- #include <queue>
- #include <utility>
- #include <vector>
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n; cin >> n;
- vector<pair<int, int>> couple(n); vector<vector<int>> g(2 * n);
- for (auto &[a, b] : couple) {
- cin >> a >> b; --a; --b; g[a].push_back(b); g[b].push_back(a);
- }
- for (int i = 0; i < 2 * n; i += 2) {
- g[i].push_back(i + 1); g[i + 1].push_back(i);
- }
- vector<int> color(2 * n, -1);
- for (int s = 0; s < 2 * n; ++s) if (color[s] == -1) {
- queue<int> q; q.push(s); color[s] = 0;
- while (!q.empty()) {
- int u = q.front(); q.pop();
- for (int v : g[u]) {
- if (color[v] == -1) color[v] = color[u] ^ 1, q.push(v);
- else if (color[v] == color[u]) { cout << "-1\n"; return 0; }
- }
- }
- }
- for (auto [a, b] : couple) cout << color[a] + 1 << ' ' << color[b] + 1 << '\n';
- }
|