# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
451222 |
2021-08-03T06:46:07 Z |
ak2006 |
Pipes (CEOI15_pipes) |
C++14 |
|
1576 ms |
28024 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
fast;
}
int maxN = 1e5 + 5,maxM = 6e6 + 5,n,m,TIMER;
vvi adj(2 * maxN);
vb vis(maxN);
vi low(maxN),in(maxN),p1(maxN),p2(maxN);
vvi bridges;
int Find1(int u)
{
if (p1[u] == u)return u;
return p1[u] = Find1(p1[u]);
}
int Find2(int u)
{
if (p2[u] == u)return u;
return p2[u] = Find2(p2[u]);
}
bool Merge1(int u,int v)
{
u = Find1(u),v = Find1(v);
if (u == v)return false;
p1[v] = u;
return true;
}
bool Merge2(int u,int v)
{
u = Find2(u),v = Find2(v);
if (u == v)return false;
p2[v] = u;
return true;
}
void dfs(int u,int p)
{
vis[u] = 1;
in[u] = low[u] = ++TIMER;
for (int v:adj[u]){
if (v == p)continue;
if (vis[v]){
low[u] = min(low[u],in[v]);
continue;
}
dfs(v,u);
low[u] = min(low[u],low[v]);
if (low[v] > in[u])
bridges.pb({u,v});
}
}
int main()
{
setIO();
cin>>n>>m;
for (int i = 1;i<=n;i++)p1[i] = p2[i] = i;
vvi edges;
for (int i = 1;i<=m;i++){
int u,v;
cin>>u>>v;
if (Merge1(u,v) or Merge2(u,v))
edges.pb({u,v});
assert((int)edges.size() <= 2 * n - 2);
}
m = (int)edges.size();
for (auto it:edges){
//cout<<it[0]<<" "<<it[1]<<endl;
adj[it[0]].pb(it[1]),adj[it[1]].pb(it[0]);
}
for (int i = 1;i<=n;i++)if (!vis[i])dfs(i,-1);
for (auto it:bridges)cout<<it[0]<<" "<<it[1]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6604 KB |
Output is correct |
2 |
Incorrect |
4 ms |
6604 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7560 KB |
Output is correct |
2 |
Incorrect |
9 ms |
7244 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
7228 KB |
Output is correct |
2 |
Incorrect |
120 ms |
7100 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
8660 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
11664 KB |
Output is correct |
2 |
Correct |
314 ms |
10984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
489 ms |
21764 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
721 ms |
23932 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1020 ms |
28012 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1203 ms |
28024 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1576 ms |
26960 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |