This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, s, t;
cin >> n >> s >> t;
vector<vector<int>> g(t);
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
--x[i]; --y[i];
g[x[i]].push_back(i);
g[y[i]].push_back(i);
}
vector<vector<int>> res(n, vector<int>(2));
vector<bool> was(n);
vector<bool> rem(n);
function<void(int)> Dfs = [&](int v) {
was[v] = true;
for (int e : g[v]) {
if (rem[e]) {
continue;
}
rem[e] = true;
int u = (x[e] ^ y[e] ^ v);
res[e][0] = v;
res[e][1] = u;
if (!was[u]) {
Dfs(u);
}
}
};
for (int i = 0; i < n; i++) {
if (!was[i]) {
Dfs(i);
}
}
for (int i = 0; i < n; i++) {
cout << res[i][0] + 1 << " " << res[i][1] + 1 << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |