# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
441202 |
2021-07-04T15:48:01 Z |
sinamhdv |
Pipes (CEOI15_pipes) |
C++11 |
|
1394 ms |
15512 KB |
// CEOI15_pipes
// 2nd solution
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 100010
int n, m;
vector<int> adj[MAXN];
bitset<MAXN> mark;
int val[MAXN], h[MAXN];
int ef[2 * MAXN], eto[2 * MAXN];
int tree[MAXN], be[MAXN];
int getroot(int x, int *dpar)
{
return dpar[x] == x ? x : dpar[x] = getroot(dpar[x], dpar);
}
bool merge(int x, int y, int *dpar)
{
x = getroot(x, dpar);
y = getroot(y, dpar);
if (x == y) return false;
dpar[x] = y;
return true;
}
void dfs1(int v, int epar = 0)
{
mark[v] = true;
for (int e : adj[v])
{
int u = ef[e] ^ eto[e] ^ v;
if (mark[u])
{
if (h[u] < h[v] && e != epar) val[u]--, val[v]++;
continue;
}
h[u] = h[v] + 1;
dfs1(u, e);
}
}
void dfs2(int v, int epar = 0)
{
mark[v] = true;
for (int e : adj[v])
{
int u = ef[e] ^ eto[e] ^ v;
if (!mark[u]) dfs2(u, e), val[v] += val[u];
}
if (epar && val[v] == 0) cout << ef[epar] << ' ' << eto[epar] << endl;
}
int32_t main(void)
{
fast_io;
cin >> n >> m;
iota(tree, tree + n + 5, 0);
iota(be, be + n + 5, 0);
int ecnt = 0;
FOR(i, 0, m)
{
int x, y;
cin >> x >> y;
if (merge(x, y, tree) || merge(x, y, be))
{
ecnt++;
ef[ecnt] = x;
eto[ecnt] = y;
adj[x].pb(ecnt);
adj[y].pb(ecnt);
}
}
FOR(i, 1, n + 1) if (!mark[i]) dfs1(i);
mark.reset();
FOR(i, 1, n + 1) if (!mark[i]) dfs2(i);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3148 KB |
Output is correct |
2 |
Correct |
6 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
3024 KB |
Output is correct |
2 |
Correct |
117 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
3916 KB |
Output is correct |
2 |
Correct |
234 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
5816 KB |
Output is correct |
2 |
Correct |
287 ms |
5260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
468 ms |
11652 KB |
Output is correct |
2 |
Correct |
420 ms |
8132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
769 ms |
13044 KB |
Output is correct |
2 |
Correct |
673 ms |
9968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
950 ms |
15460 KB |
Output is correct |
2 |
Correct |
926 ms |
10640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1177 ms |
15512 KB |
Output is correct |
2 |
Correct |
1136 ms |
10548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1394 ms |
14796 KB |
Output is correct |
2 |
Correct |
1337 ms |
11648 KB |
Output is correct |