# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
109989 |
2019-05-08T14:17:45 Z |
someone_aa |
Pipes (CEOI15_pipes) |
C++17 |
|
1634 ms |
13932 KB |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
vector<int>g[maxn];
int n, m;
int tin[maxn], low[maxn];
class dsu {
public:
int uparent[maxn], usize[maxn];
void init() {
for(int i=0;i<=n;i++) {
uparent[i] = i;
usize[i] = 1;
}
}
int uroot(int x) {
while(x != uparent[x]) {
x = uparent[x];
}
return x;
}
bool connected(int x, int y) {
return uroot(x) == uroot(y);
}
void unite(int x, int y) {
x = uroot(x);
y = uroot(y);
if(usize[x] > usize[y]) {
uparent[y] = x;
usize[x] += usize[y];
}
else {
uparent[x] = y;
usize[y] += usize[x];
}
}
}one, two;
int br;
bool visited[maxn];
void dfs(int node, int p) {
tin[node] = br++;
low[node] = tin[node];
visited[node] = true;
bool parent_edge = false;
for(int i:g[node]) {
if(i == p) {
if(parent_edge) low[node] = min(low[node], tin[i]);
parent_edge = true;
continue;
}
if(visited[i]) {
low[node] = min(low[node], tin[i]);
}
else {
dfs(i, node);
low[node] = min(low[node], low[i]);
if(low[i] > tin[node]) {
cout<<i<<" "<<node<<"\n";
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
int u, v;
one.init();
two.init();
for(int i=0;i<m;i++) {
cin>>u>>v;
if(!one.connected(u, v)) {
one.unite(u, v);
g[u].pb(v);
g[v].pb(u);
}
else {
if(two.connected(u, v)) continue;
two.unite(u, v);
g[u].pb(v);
g[v].pb(u);
}
}
for(int i=1;i<=n;i++) {
if(!visited[i]) {
dfs(i, -1);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3172 KB |
Output is correct |
2 |
Correct |
8 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
3080 KB |
Output is correct |
2 |
Correct |
116 ms |
2948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
3808 KB |
Output is correct |
2 |
Correct |
236 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
374 ms |
5364 KB |
Output is correct |
2 |
Correct |
315 ms |
5184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
10636 KB |
Output is correct |
2 |
Correct |
452 ms |
7680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
789 ms |
11740 KB |
Output is correct |
2 |
Correct |
774 ms |
9388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1114 ms |
13932 KB |
Output is correct |
2 |
Correct |
1012 ms |
9860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1344 ms |
13928 KB |
Output is correct |
2 |
Correct |
1286 ms |
9856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1634 ms |
13400 KB |
Output is correct |
2 |
Correct |
1481 ms |
11028 KB |
Output is correct |