# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
658135 |
2022-11-12T09:12:18 Z |
FatihSolak |
Pipes (CEOI15_pipes) |
C++17 |
|
964 ms |
14204 KB |
#include <bits/stdc++.h>
#define N 100005
using namespace std;
struct DSU{
vector<int> par;
void init(int n){
par.assign(n+1,0);
for(int i = 1;i<=n;i++){
par[i] = i;
}
}
int find(int a){
if(a == par[a])return a;
return par[a] = find(par[a]);
}
bool merge(int a,int b){
a = find(a);
b = find(b);
if(a == b)
return 0;
par[a] = b;
return 1;
}
};
int dep[N];
int mini[N];
bool vis[N];
vector<int> adj[N];
void dfs(int v,int par){
vis[v] = 1;
mini[v] = dep[v];
bool ok = 0;
for(auto u:adj[v]){
if(u == par && !ok){
ok = 1;
continue;
}
if(!vis[u]){
dep[u] = dep[v] + 1;
dfs(u,v);
mini[v] = min(mini[v],mini[u]);
}
else{
mini[v] = min(mini[v],dep[u]);
}
}
if(par != 0 && dep[v] == mini[v]){
cout << par << ' ' << v << '\n';
}
}
void solve(){
int n,m;
cin >> n >> m;
DSU d1,d2;
d1.init(n);
d2.init(n);
for(int i = 1;i<=m;i++){
int a,b;
cin >> a >> b;
if(d1.merge(a,b)){
adj[a].push_back(b);
adj[b].push_back(a);
}
else if(d2.merge(a,b)){
adj[a].push_back(b);
adj[b].push_back(a);
}
}
for(int i = 1;i<=n;i++){
if(!vis[i])
dfs(i,0);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3156 KB |
Output is correct |
2 |
Correct |
4 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
2960 KB |
Output is correct |
2 |
Correct |
77 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
3764 KB |
Output is correct |
2 |
Correct |
190 ms |
3256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
5328 KB |
Output is correct |
2 |
Correct |
190 ms |
5040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
376 ms |
10652 KB |
Output is correct |
2 |
Correct |
281 ms |
7188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
11828 KB |
Output is correct |
2 |
Correct |
436 ms |
8964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
662 ms |
14048 KB |
Output is correct |
2 |
Correct |
632 ms |
9164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
835 ms |
14204 KB |
Output is correct |
2 |
Correct |
765 ms |
9212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
964 ms |
13476 KB |
Output is correct |
2 |
Correct |
911 ms |
10556 KB |
Output is correct |