# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527146 |
2022-02-17T02:43:59 Z |
chicken337 |
Pipes (CEOI15_pipes) |
C++14 |
|
998 ms |
14160 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int v, e, ID = 0;
vector<int> num, low;
vector<int> adj[MAXN];
struct UFDS{
vector<int> p;
vector<char> r;
UFDS(){
p.resize(v); r.resize(v);
for(int i = 0; i < v; i ++)
p[i] = i, r[i] = 0;
}
int root(int x){
if(p[x] == x) return x;
return p[x] = root(p[x]);
}
bool connected(int x, int y){
return root(x) == root(y);
}
void connect(int x, int y){
x = root(x), y = root(y);
if(r[x] < r[y]) swap(x, y);
if(r[x] == r[y]) r[x] ++;
p[y] = x;
}
};
void dfs(int x, int par){
num[x] = low[x] = ID ++;
for(int nxt : adj[x]){
if(num[nxt] == -1){
dfs(nxt, x);
if(num[x] < low[nxt])
cout << x+1 << ' ' << nxt+1 << '\n';
low[x] = min(low[x], low[nxt]);
} else if(nxt != par){
low[x] = min(low[x], num[nxt]);
} else par = -1;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> v >> e; int a, b;
UFDS ua = UFDS();
UFDS ub = UFDS();
num.assign(v, -1);
low.assign(v, -1);
for(int i = 0; i < e; i ++){
cin >> a >> b;
if(!ua.connected(a-1, b-1)){
adj[a-1].push_back(b-1);
adj[b-1].push_back(a-1);
ua.connect(a-1, b-1);
} else if(!ub.connected(a-1, b-1)){
adj[a-1].push_back(b-1);
adj[b-1].push_back(a-1);
ub.connect(a-1, b-1);
}
}
for(int i = 0; i < v; i ++)
if(num[i] == -1)
dfs(i, -1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3148 KB |
Output is correct |
2 |
Correct |
4 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2984 KB |
Output is correct |
2 |
Correct |
91 ms |
2840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
3652 KB |
Output is correct |
2 |
Correct |
173 ms |
3208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
5296 KB |
Output is correct |
2 |
Correct |
228 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
10676 KB |
Output is correct |
2 |
Correct |
304 ms |
7152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
464 ms |
11892 KB |
Output is correct |
2 |
Correct |
464 ms |
9092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
677 ms |
14036 KB |
Output is correct |
2 |
Correct |
624 ms |
9372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
794 ms |
14160 KB |
Output is correct |
2 |
Correct |
776 ms |
9200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
998 ms |
13508 KB |
Output is correct |
2 |
Correct |
967 ms |
10752 KB |
Output is correct |