# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378453 | 2021-03-16T20:09:55 Z | AriaH | Pipes (CEOI15_pipes) | C++11 | 1581 ms | 14316 KB |
/** I can do this all day **/ #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() const int N = 1e5 + 5; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll inf = 8e18; const int LOG = 22; int par[N * 2]; 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; } int n, m, H[N], Up[N]; vector < int > G[N]; void dfs(int v, int P = -1) { Up[v] = H[v]; int id = -1; for(auto u : G[v]) { id ++; if(u == P) continue; if(H[u]) { Up[v] = min(Up[v], H[u]); } else { H[u] = H[v] + 1; dfs(u, v); if(Up[u] > H[v] && (id > 0 && G[v][id - 1] == u) == 0 && (id + 1 < SZ(G[v]) && G[v][id + 1] == u) == 0) { printf("%d %d\n", v, u); } Up[v] = min(Up[v], Up[u]); } } } int main() { for(int i = 0; i < N << 1; i ++) par[i] = i; scanf("%d%d", &n, &m); for(int i = 1; i <= m; i ++) { int a, b; scanf("%d%d", &a, &b); if(unify(a, b)) { G[a].push_back(b); G[b].push_back(a); } else { if(unify(a + n, b + n)) { G[a].push_back(b); G[b].push_back(a); } } } for(int i = 1; i <= n; i ++) sort(all(G[i])); for(int i = 1; i <= n; i ++) { if(H[i]) continue; H[i] = 1; dfs(i); } return 0; } /** test corner cases(n = 1?) watch for overflow or minus indices **/
Compilation message
# | 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 | 3948 KB | Output is correct |
2 | Correct | 7 ms | 3692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 138 ms | 3820 KB | Output is correct |
2 | Correct | 135 ms | 3648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 227 ms | 4460 KB | Output is correct |
2 | Correct | 279 ms | 4024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 386 ms | 6124 KB | Output is correct |
2 | Correct | 356 ms | 5612 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 538 ms | 11116 KB | Output is correct |
2 | Correct | 466 ms | 7532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 796 ms | 12140 KB | Output is correct |
2 | Correct | 800 ms | 9324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1066 ms | 14316 KB | Output is correct |
2 | Correct | 998 ms | 9196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1301 ms | 14188 KB | Output is correct |
2 | Correct | 1242 ms | 9068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1581 ms | 13796 KB | Output is correct |
2 | Correct | 1581 ms | 10988 KB | Output is correct |