# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
851490 |
2023-09-20T01:23:25 Z |
Nhoksocqt1 |
Pipes (CEOI15_pipes) |
C++17 |
|
876 ms |
49904 KB |
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 100005;
vector<int> adj[MAXN];
int lab[MAXN][2], numNode, numEdge;
int root(int it, int u) {
return (lab[u][it] < 0) ? u : (lab[u][it] = root(it, lab[u][it]));
}
bool join(int it, int u, int v) {
u = root(it, u), v = root(it, v);
if(u == v)
return (false);
if(lab[u][it] > lab[v][it])
swap(u, v);
lab[u][it] += lab[v][it];
lab[v][it] = u;
return (true);
}
void dfs(int u, int p = -1) {
lab[u][0] = lab[u][1] = ++lab[0][0];
bool edgep(1);
for (int v : adj[u]) {
if(v == p && edgep) {
edgep = 0;
continue;
}
if(!lab[v][1]) {
dfs(v, u);
lab[u][0] = min(lab[u][0], lab[v][0]);
if(lab[v][0] >= lab[v][1])
cout << u << ' ' << v << '\n';
} else {
lab[u][0] = min(lab[u][0], lab[v][1]);
}
}
}
void process() {
cin >> numNode >> numEdge;
for (int i = 1; i <= numNode; ++i)
lab[i][0] = lab[i][1] = -1;
for (int i = 0; i < numEdge; ++i) {
int u, v;
cin >> u >> v;
if(join(0, u, v)) {
adj[u].push_back(v);
adj[v].push_back(u);
} else
if(join(1, u, v)) {
adj[u].push_back(v);
adj[v].push_back(u);
}
}
for (int i = 0; i <= numNode; ++i)
lab[i][0] = lab[i][1] = 0;
for (int i = 1; i <= numNode; ++i) {
if(!lab[i][1])
dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
process();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3928 KB |
Output is correct |
2 |
Correct |
5 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
3588 KB |
Output is correct |
2 |
Correct |
84 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
4380 KB |
Output is correct |
2 |
Correct |
150 ms |
3864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
237 ms |
6116 KB |
Output is correct |
2 |
Correct |
185 ms |
5540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
11012 KB |
Output is correct |
2 |
Runtime error |
263 ms |
25260 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
441 ms |
12136 KB |
Output is correct |
2 |
Runtime error |
472 ms |
42356 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
585 ms |
14072 KB |
Output is correct |
2 |
Runtime error |
621 ms |
49904 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
776 ms |
18328 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
876 ms |
30668 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |