# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
668734 |
2022-12-04T20:24:13 Z |
AmirAli_H1 |
Pipes (CEOI15_pipes) |
C++17 |
|
5000 ms |
5876 KB |
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define debug(x) cerr << #x << ": " << x << endl;
#define kill(x) cout << x << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
int n, m;
const int maxn = 1e5 + 5;
int p[maxn], sz[maxn];
int px[maxn], szx[maxn];
vector<pii> adj[maxn];
vector<pii> E; bitset<2 * maxn> ans;
bitset<maxn> mark;
int h[maxn], mn[maxn];
void dfs(int v, int j = -1) {
mark[v] = 1; mn[v] = h[v];
for (auto f : adj[v]) {
int u = f.F, i = f.S;
if (!mark[u]) {
h[u] = h[v] + 1;
dfs(u, i);
mn[v] = min(mn[v], mn[u]);
}
else if (i != j) {
mn[v] = min(mn[v], h[u]);
}
}
if (mn[v] >= h[v] && j != -1) {
ans[j] = 1;
}
}
int get(int a) {
return ((p[a] == a) ? a : p[a] = get(p[a]));
}
void merge(int a, int b) {
a = get(a); b = get(b);
if (a == b) return ;
if (sz[a] > sz[b]) swap(a, b);
p[a] = b; sz[b] += sz[a]; sz[a] = 0;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
iota(p, p + n, 0); fill(sz, sz + n, 1);
iota(px, px + n, 0); fill(szx, szx + n, 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v; u--; v--;
bool flag = 0;
if (!flag && get(u) != get(v)) {
flag = 1;
merge(u, v);
adj[u].pb(Mp(v, i)); adj[v].pb(Mp(u, i));
}
swap(p, px); swap(sz, szx);
if (!flag && get(u) != get(v)) {
flag = 1;
merge(u, v);
adj[u].pb(Mp(v, i)); adj[v].pb(Mp(u, i));
}
swap(p, px); swap(sz, szx);
if (flag) E.pb(Mp(u, v));
}
for (int i = 0; i < n; i++) {
if (!mark[i]) dfs(i);
}
for (int i = 0; i < 2 * n; i++) {
if (ans[i]) {
cout << E[i].F + 1 << sep << E[i].S + 1 << endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
4244 KB |
Mismatched edge |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3094 ms |
4984 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5065 ms |
4804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5059 ms |
5384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5027 ms |
5568 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5061 ms |
5548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5071 ms |
5780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5081 ms |
5876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5080 ms |
5872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5092 ms |
5496 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |