# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
623836 | Alma | Pipes (CEOI15_pipes) | C++17 | 5068 ms | 65536 KiB |
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;
#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;
const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;
void setIO (string fileName) {
ios::sync_with_stdio(false);
cin.tie(NULL);
if (fileName != "std") {
freopen((fileName + ".in").c_str(), "r", stdin);
freopen((fileName + ".out").c_str(), "w", stdout);
}
}
vi st, path, par;
vvi adj;
int uFind(int u) {
if (par[u] == u) return u;
return par[u] = uFind(par[u]);
}
void uJoin (int u, int v) {
int a = uFind(u), b = uFind(v);
par[a] = b;
}
void dfs (int u, int p) {
st[u] = 1;
path.push_back(u);
for (auto v: adj[u]) {
if (v == p) continue;
if (st[v] == 1) {
for (int i = (int)path.size()-1; i >= 0; i--) {
if (path[i] == v) break;
uJoin(v, path[i]);
}
}
if (st[v] == 0) dfs(v, u);
}
path.pop_back();
st[u] = 2;
}
void dfs2 (int u, int p) {
st[u] = 1;
for (auto v: adj[u]) {
if (v == p) continue;
if (uFind(u) != uFind(v))
cout << u+1 << ' ' << v+1 << '\n';
if (st[v] == 0) dfs2(v, u);
}
}
int main() {
setIO("std");
int n, m, u, v;
cin >> n >> m;
adj = vvi(n);
st = vi(n, 0);
par = vi(n);
for (int i = 0; i < n; i++)
par[i] = i;
while (m--) {
cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 0; i < n; i++) {
if (st[i] == 0) dfs(i, -1);
}
st = vi(n, 0);
for (int i = 0; i < n; i++) {
if (st[i] == 0) dfs2(i, -1);
}
return 0;
}
Compilation message (stderr)
# | 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... |