# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874944 |
2023-11-18T07:06:10 Z |
Bahamin |
Pipes (CEOI15_pipes) |
C++17 |
|
766 ms |
15964 KB |
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
#define ar array
#define ll long long
#define ld long double
#define sze(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define sui cout.tie(NULL); cin.tie(NULL); ios_base::sync_with_stdio(false)
#define mset(a, x) memset(a, x, sizeof(a))
typedef priority_queue <int, vector<int>, greater<int> > max_heap;
typedef priority_queue <int> min_heap;
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
int par[2][MAX_N];
vector<pair<int, int>> adj[MAX_N];
int getpar(int u, int k)
{
return (par[k][u] == u ? u : par[k][u] = getpar(par[k][u], k));
}
bool merge(int u, int v, int k)
{
u = getpar(u, k), v = getpar(v, k);
if (u == v) return false;
par[k][v] = u;
return true;
}
int dp[MAX_N];
int he[MAX_N];
void dfs(int u, int h, int p, int p2)
{
he[u] = h;
dp[u] = INF;
for (pair<int, int> v : adj[u])
{
if (v.second == p) continue;
if (he[v.first] == -1) dfs(v.first, h + 1, v.second, u), dp[u] = min(dp[v.first], dp[u]);
else dp[u] = min(dp[u], min(he[v.first], h));
}
if (dp[u] >= h && p2 != -1) cout << u << " " << p2 << endl;
}
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
par[0][i] = par[1][i] = i;
dp[i] = INF;
he[i] = -1;
adj[i].clear();
}
int cnt = 0;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
if (merge(a, b, 0)) cnt++, adj[a].push_back(make_pair(b, cnt)), adj[b].push_back(make_pair(a, cnt));
else if (merge(a, b, 1)) cnt++, adj[a].push_back(make_pair(b, cnt)), adj[b].push_back(make_pair(a, cnt));
}
for (int i = 1; i <= n; i++)
{
if (he[i] == -1) dfs(i, 0, -1, -1);
}
}
int main() {
sui;
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4000 KB |
Output is correct |
2 |
Correct |
3 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
3684 KB |
Output is correct |
2 |
Correct |
62 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
4636 KB |
Output is correct |
2 |
Correct |
125 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
6396 KB |
Output is correct |
2 |
Correct |
161 ms |
5736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
12508 KB |
Output is correct |
2 |
Correct |
226 ms |
8788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
13644 KB |
Output is correct |
2 |
Correct |
378 ms |
9996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
518 ms |
15964 KB |
Output is correct |
2 |
Correct |
486 ms |
11100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
645 ms |
15952 KB |
Output is correct |
2 |
Correct |
598 ms |
11128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
766 ms |
15188 KB |
Output is correct |
2 |
Correct |
756 ms |
11528 KB |
Output is correct |