# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034712 |
2024-07-25T17:02:09 Z |
vjudge1 |
Pipes (CEOI15_pipes) |
C++17 |
|
174 ms |
19284 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], par[N];
int timer=0;
void dfs(int at) {
bool ck=0;
id[at]=low[at]=++timer;
for(int to:g[at]) {
if(to == par[at] and ck==0) {
ck=1;
continue;
}
if(id[to]) {
low[at]=min(low[at], id[to]);
} else {
par[to]=at;
dfs(to);
low[at]=min(low[at], low[to]);
}
}
if(low[at] == id[at] and 0!=par[at]) {
cout << at << " " << par[at] << "\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);
}
}
for(int i= 1;i<=n;i++) {
if(!id[i]) {
dfs(i);
}
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:90:6: warning: unused variable 'cnt' [-Wunused-variable]
90 | int cnt=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 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 |
67 ms |
7160 KB |
Output is correct |
2 |
Correct |
75 ms |
6736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
11600 KB |
Output is correct |
2 |
Correct |
122 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
174 ms |
19284 KB |
Memory limit exceeded |
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 |
- |
# |
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 |
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 |
- |