# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
451421 |
2021-08-03T07:48:17 Z |
ak2006 |
Pipes (CEOI15_pipes) |
C++14 |
|
1522 ms |
24176 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,n,m,TIMER;
vvi adj(maxN);
vi low(maxN),in(maxN),p1(maxN,-1),p2(maxN,-1);
int Find1(int u)
{
if (p1[u] < 0)return u;
return p1[u] = Find1(p1[u]);
}
int Find2(int u)
{
if (p2[u] < 0)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;
if (p1[v] > p1[u])swap(u,v);
p1[u] += p1[v];
p1[v] = u;
return true;
}
bool Merge2(int u,int v)
{
u = Find2(u),v = Find2(v);
if (u == v)return false;
if (p2[v] > p2[u])swap(u,v);
p2[u] += p2[v];
p2[v] = u;
return true;
}
void dfs(int u,int p)
{
in[u] = low[u] = ++TIMER;
bool is = false;
for (int v:adj[u]){
if (v != p or is){
if (in[v])
low[u] = min(low[u],in[v]);
else
dfs(v,u),low[u] = min(low[u],low[v]);
}
else is = true;
}
if (low[u] == in[u] && p!=-1)cout<<u<<" "<<p<<'\n';
}
int main()
{
setIO();
cin>>n>>m;
int cnt = 0;
for (int i = 1;i<=m;i++){
int u,v;
cin>>u>>v;
if (Merge1(u,v) or Merge2(u,v))
adj[u].pb(v),adj[v].pb(u),cnt++;
assert(cnt <= 2 * n - 2);
}
for (int i = 1;i<=n;i++)if (!in[i])dfs(i,-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4172 KB |
Output is correct |
2 |
Correct |
3 ms |
4172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4556 KB |
Output is correct |
2 |
Correct |
9 ms |
4428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
4548 KB |
Output is correct |
2 |
Correct |
120 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
5124 KB |
Output is correct |
2 |
Correct |
276 ms |
11632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
6464 KB |
Output is correct |
2 |
Correct |
322 ms |
6040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
496 ms |
11020 KB |
Output is correct |
2 |
Correct |
440 ms |
7668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
12164 KB |
Output is correct |
2 |
Runtime error |
728 ms |
20232 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1034 ms |
13996 KB |
Output is correct |
2 |
Runtime error |
918 ms |
23948 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1156 ms |
13988 KB |
Output is correct |
2 |
Runtime error |
1218 ms |
24140 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1522 ms |
13400 KB |
Output is correct |
2 |
Runtime error |
1444 ms |
24176 KB |
Memory limit exceeded |