# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034708 |
2024-07-25T16:57:30 Z |
vjudge1 |
Pipes (CEOI15_pipes) |
C++17 |
|
186 ms |
16980 KB |
#include <bits/stdc++.h>
using namespace std;
#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());
//#pragma GCC optimize("O3,unroll-loops")
/**
* Author: Lukas Polacek
* Date: 2009-10-26
* License: CC0
* Source: folklore
* Description: Disjoint-set data structure.
* Time: $O(\alpha(N))$
*/
const int N = 30'010;
namespace d1 {
int e[N];
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool sameSet(int a, int b) { return find(a) == find(b); }
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;
}
};
namespace d2 {
int e[N];
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool sameSet(int a, int b) { return find(a) == find(b); }
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;
}
};
vt<int> g[N+1];
int low[N+1], id[N+1];
int timer=0;
void dfs(int &at, int &par) {
bool ck=0;
id[at]=low[at]=++timer;
for(int &to:g[at]) {
if(to == par and ck==0) {
ck=1;
continue;
}
if(id[to]) {
low[at]=min(low[at], id[to]);
} else {
dfs(to, at);
low[at]=min(low[at], low[to]);
}
}
if(low[at] == id[at] and at!=par) {
cout << at << " " << par << "\n";
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
int u, v;
int cnt=0;
memset(d1::e, -1, sizeof d1::e);
memset(d2::e, -1, sizeof d2::e);
rep(i, 0, m) {
cin >> u >> v;
if(d1::join(u, v) || d2::join(u, v)) {
g[u].pb(v);
g[v].pb(u);
cnt+=2;
}
}
assert(cnt<=4*n);
for(int i= 1;i<=n;i++) {
if(!id[i])
dfs(i, i);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
3 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
4724 KB |
Output is correct |
2 |
Correct |
58 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
7336 KB |
Output is correct |
2 |
Correct |
122 ms |
7932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
12120 KB |
Output is correct |
2 |
Runtime error |
186 ms |
16980 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2392 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
2392 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2392 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |