# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
97605 |
2019-02-17T12:47:13 Z |
dalgerok |
Pipes (CEOI15_pipes) |
C++14 |
|
1242 ms |
10656 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, m;
int p[2][N];
int tin[N], fup[N], timer;
int E, Y[4 * N], lst[N], prv[4 * N];
void add_edge(int x, int y){
Y[++E] = y;
if(lst[x] == 0){
lst[x] = E;
}
else{
prv[E] = lst[x];
lst[x] = E;
}
Y[++E] = x;
if(lst[y] == 0){
lst[y] = E;
}
else{
prv[E] = lst[y];
lst[y] = E;
}
}
int dsu_get(int x, int v){
return p[x][v] == v ? v : p[x][v] = dsu_get(x, p[x][v]);
}
void dfs(int v, int pr = 0){
tin[v] = fup[v] = ++timer;
bool was = false;
for(int i = lst[v]; i != 0; i = prv[i]){
int to = Y[i];
if(to == pr){
if(was){
fup[v] = min(fup[v], tin[to]);
}
was = true;
continue;
}
if(!tin[to]){
dfs(to, v);
if(fup[to] > tin[v]){
cout << v << " " << to << "\n";
}
fup[v] = min(fup[v], fup[to]);
}
else{
fup[v] = min(fup[v], tin[to]);
}
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
p[0][i] = p[1][i] = i;
}
for(int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
if(dsu_get(0, x) == dsu_get(0, y)){
if(dsu_get(1, x) == dsu_get(1, y)){
continue;
}
p[1][dsu_get(1, x)] = dsu_get(1, y);
}
else{
p[0][dsu_get(0, x)] = dsu_get(0, y);
}
add_edge(x, y);
}
for(int i = 1; i <= n; i++){
if(!tin[i]){
//cout << "KEK " << i << " " << tin[i] << "\n";
dfs(i);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
760 KB |
Output is correct |
2 |
Correct |
94 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
1336 KB |
Output is correct |
2 |
Correct |
192 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
323 ms |
2808 KB |
Output is correct |
2 |
Correct |
236 ms |
2436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
387 ms |
7672 KB |
Output is correct |
2 |
Correct |
376 ms |
4540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
8696 KB |
Output is correct |
2 |
Correct |
592 ms |
6136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
814 ms |
10652 KB |
Output is correct |
2 |
Correct |
789 ms |
6208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1034 ms |
10656 KB |
Output is correct |
2 |
Correct |
1059 ms |
6336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1242 ms |
10188 KB |
Output is correct |
2 |
Correct |
1155 ms |
7308 KB |
Output is correct |