# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378453 | AriaH | Pipes (CEOI15_pipes) | C++11 | 1581 ms | 14316 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.
/** I can do this all day **/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Mp make_pair
#define SZ(x) (int)x.size()
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
int par[N * 2];
int get(int x) { return (x == par[x]? x : par[x] = get(par[x])); }
int unify(int v, int u)
{
v = get(v), u = get(u);
if(v == u)
{
return 0;
}
par[u] = v;
return 1;
}
int n, m, H[N], Up[N];
vector < int > G[N];
void dfs(int v, int P = -1)
{
Up[v] = H[v];
int id = -1;
for(auto u : G[v])
{
id ++;
if(u == P) continue;
if(H[u])
{
Up[v] = min(Up[v], H[u]);
}
else
{
H[u] = H[v] + 1;
dfs(u, v);
if(Up[u] > H[v] && (id > 0 && G[v][id - 1] == u) == 0 && (id + 1 < SZ(G[v]) && G[v][id + 1] == u) == 0)
{
printf("%d %d\n", v, u);
}
Up[v] = min(Up[v], Up[u]);
}
}
}
int main()
{
for(int i = 0; i < N << 1; i ++) par[i] = i;
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
if(unify(a, b))
{
G[a].push_back(b);
G[b].push_back(a);
}
else
{
if(unify(a + n, b + n))
{
G[a].push_back(b);
G[b].push_back(a);
}
}
}
for(int i = 1; i <= n; i ++) sort(all(G[i]));
for(int i = 1; i <= n; i ++)
{
if(H[i]) continue;
H[i] = 1;
dfs(i);
}
return 0;
}
/** test corner cases(n = 1?) watch for overflow or minus indices **/
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... |