# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034679 |
2024-07-25T16:37:45 Z |
vjudge1 |
Pipes (CEOI15_pipes) |
C++17 |
|
1058 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define vt vector
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<class T> bool chmin(T& a, const T& b) {
return b<a?a=b, 1:0;
}
template<class T> bool chmax(T& a, const T& b) {
return a<b?a=b, 1:0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
/**
* Author: Lukas Polacek
* Date: 2009-10-26
* License: CC0
* Source: folklore
* Description: Disjoint-set data structure.
* Time: $O(\alpha(N))$
*/
struct UF {
vi e;
UF(int n) : e(n, -1) {}
bool sameSet(int a, int b) { return find(a) == find(b); }
int size(int x) { return -e[find(x)]; }
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
vt<pii> e;
int u, v;
UF d1(n+1), d2(n+1);
vt<vt<int>> g(n+1);
rep(i, 0, m) {
cin >> u >> v;
// if(d1.join(u, v)) {
g[u].pb(v);
g[v].pb(u);
// } else if(d2.join(u, v)) {
// g[u].pb(v);
// g[v].pb(u);
// }
}
vt<int> low(n+1), id(n+1);
int timer=0;
auto dfs = [&](int at, int par, auto &&self) -> void {
bool ck=0;
id[at]=low[at]=++timer;
for(auto to:g[at]) {
if(to == par and ck==0) {
ck=1;
continue;
}
if(id[to]) {
low[at]=min(low[at], id[to]);
} else {
self(to, at, self);
low[at]=min(low[at], low[to]);
}
}
if(low[at] == id[at] and at!=par) {
cout << at << " " << par << "\n";
}
};
for(int i= 1;i<=n;i++) {
if(!id[i])
dfs(i, i, dfs);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
14168 KB |
Output is correct |
2 |
Correct |
70 ms |
13392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
131 ms |
21588 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
262 ms |
37200 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
342 ms |
48100 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
629 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
816 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
909 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1058 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |