# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378447 |
2021-03-16T19:50:40 Z |
AriaH |
Pipes (CEOI15_pipes) |
C++11 |
|
1556 ms |
65536 KB |
/** I can do this all day **/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Mp make_pair
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }
struct dsu
{
int par[N];
void init()
{
iota(par, par + N, 0);
}
int get(int x)
{
return (x == par[x]? x : par[x] = get(par[x]));
}
int unify(int v, int u)
{
v = get(v), u = get(u);
if(v == u)
{
return 0;
}
par[u] = v;
return 1;
}
} A, B;
int n, m, H[N], Up[N];
vector < pii > G[N];
void dfs(int v, int last)
{
Up[v] = H[v];
for(auto y : G[v])
{
int u = y.F, id = y.S;
if(id == last) continue;
if(H[u])
{
Up[v] = min(Up[v], H[u]);
}
else
{
H[u] = H[v] + 1;
dfs(u, id);
if(Up[u] > H[v])
{
printf("%d %d\n", v, u);
}
Up[v] = min(Up[v], Up[u]);
}
}
}
int main()
{
A.init(), B.init();
scanf("%d%d", &n, &m);
int ptr = 0;
for(int i = 1; i <= m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
if(A.unify(a, b))
{
G[a].push_back(Mp(b, ++ ptr));
G[b].push_back(Mp(a, ptr));
}
else
{
if(B.unify(a, b))
{
G[a].push_back(Mp(b, ++ ptr));
G[b].push_back(Mp(a, ptr));
}
}
}
for(int i = 1; i <= n; i ++)
{
if(H[i]) continue;
H[i] = 1;
dfs(i, 0);
}
return 0;
}
/** test corner cases(n = 1?) watch for overflow or minus indices **/
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
81 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
86 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4076 KB |
Output is correct |
2 |
Correct |
7 ms |
3948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
4460 KB |
Output is correct |
2 |
Correct |
128 ms |
4076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
5228 KB |
Output is correct |
2 |
Correct |
255 ms |
4460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
6984 KB |
Output is correct |
2 |
Correct |
329 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
498 ms |
12268 KB |
Output is correct |
2 |
Runtime error |
473 ms |
27116 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
823 ms |
13804 KB |
Output is correct |
2 |
Runtime error |
799 ms |
43244 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1010 ms |
16364 KB |
Output is correct |
2 |
Runtime error |
987 ms |
52588 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1247 ms |
16312 KB |
Output is correct |
2 |
Runtime error |
1261 ms |
64108 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1515 ms |
16108 KB |
Output is correct |
2 |
Runtime error |
1556 ms |
65536 KB |
Memory limit exceeded |