# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
728064 |
2023-04-21T22:32:04 Z |
n0sk1ll |
Pipes (CEOI15_pipes) |
C++11 |
|
985 ms |
51444 KB |
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
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;
ff(c,0,2) fff(i,1,n) up[c][i]=-1;
while (m--)
{
int u,v; cin>>u>>v;
if (dsu(0,u,v) || dsu(1,u,v)) edge[u].pb(v),edge[v].pb(u);
}
fff(i,1,n) if (up[0][i]<0) dfs(i);
}
//Note to self: Check for overflow
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3156 KB |
Output is correct |
2 |
Correct |
5 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
3020 KB |
Output is correct |
2 |
Correct |
86 ms |
2832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
3660 KB |
Output is correct |
2 |
Correct |
163 ms |
3268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
5296 KB |
Output is correct |
2 |
Runtime error |
213 ms |
18732 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
10188 KB |
Output is correct |
2 |
Runtime error |
295 ms |
25780 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
501 ms |
11308 KB |
Output is correct |
2 |
Runtime error |
568 ms |
42304 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
688 ms |
13264 KB |
Output is correct |
2 |
Runtime error |
690 ms |
51444 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
846 ms |
16736 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
985 ms |
29064 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |