# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
728073 |
2023-04-21T22:57:36 Z |
n0sk1ll |
Pipes (CEOI15_pipes) |
C++17 |
|
968 ms |
13348 KB |
#include <vector>
#include <iostream>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
using namespace std;
int up[2][100005];
int Up(bool c, int x)
{
if (up[c][x]<0) return x;
return up[c][x]=Up(c,up[c][x]);
}
bool dsu(bool c, int a, int b)
{
a=Up(c,a),b=Up(c,b);
if (a==b) return false;
if (up[c][a]<up[c][b]) swap(a,b);
up[c][b]+=up[c][a],up[c][a]=b;
return true;
}
int par[100010];
int idx[100010];
int lowl[100010];
int nt;
vector<int> edge[100010];
void dfs(int x){
idx[x] = lowl[x] = ++nt;
bool cl = false;
for(int y:edge[x]){
if(par[x] == y && !cl){
cl=true; continue;
}
if(!idx[y]){
par[y]=x;
dfs(y);
lowl[x] = min(lowl[x], lowl[y]);
} else lowl[x] = min(lowl[x], idx[y]);
}
if(par[x] && idx[x]==lowl[x]) cout<<x<<" "<<par[x]<<"\n";
}
int main()
{
FAST;
int n,m; cin>>n>>m;
for (int c=0;c<2;c++) for (int i=1;i<=n;i++) up[c][i]=-1;
while (m--)
{
int u,v; cin>>u>>v;
if (dsu(0,u,v) || dsu(1,u,v)) edge[u].push_back(v),edge[v].push_back(u);
}
for (int i=1;i<=n;i++) if (up[0][i]<0) dfs(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3156 KB |
Output is correct |
2 |
Correct |
4 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
2972 KB |
Output is correct |
2 |
Correct |
80 ms |
2852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
3644 KB |
Output is correct |
2 |
Correct |
166 ms |
3256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
5228 KB |
Output is correct |
2 |
Correct |
202 ms |
4924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
320 ms |
10188 KB |
Output is correct |
2 |
Correct |
280 ms |
7620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
494 ms |
11236 KB |
Output is correct |
2 |
Correct |
455 ms |
8780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
640 ms |
13336 KB |
Output is correct |
2 |
Correct |
596 ms |
9904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
812 ms |
13348 KB |
Output is correct |
2 |
Correct |
776 ms |
9896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
968 ms |
12696 KB |
Output is correct |
2 |
Correct |
882 ms |
10444 KB |
Output is correct |