# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
671893 |
2022-12-14T08:21:20 Z |
radinr85 |
Pipes (CEOI15_pipes) |
C++14 |
|
929 ms |
65536 KB |
//radinr85
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef deque<int> dq;
typedef long double ld;
typedef pair<int , int> pii;
typedef priority_queue<int> pq;
const int maxn = 3e6;
const ll mod = 1e9+7;
#define F first
#define S second
#define endl "\n"
#define pb push_back
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
const int N = 1e5 + 1;
vector<int> ver[N];
bitset<N> mark;
int par[N][2];
int sz[N][2];
int cnt[N];
int n , m;
int get_par(int u , int x) {
return par[u][x] == u ? u : par[u][x] = get_par(par[u][x] , x);
}
void merge(int u , int v) {
int u1 = get_par(u , 0);
int u2 = get_par(v , 0);
if(u1 == u2) {
u1 = get_par(u , 1);
u2 = get_par(v , 1);
if(u1 != u2) {
if(sz[u1][1] > sz[u2][1])
swap(u1 , u2);
par[u1][1] = u2;
sz[u2][1] += sz[u1][1];
ver[u].pb(v);
ver[v].pb(u);
}
}
else {
if(sz[u1][0] > sz[u2][0])
swap(u1 , u2);
par[u1][0] = u2;
sz[u2][0] += sz[u1][0];
ver[u].pb(v);
ver[v].pb(u);
}
}
void DFS(int u) {
mark[u] = 1;
int multi = 0;
for(auto v : ver[u]) {
if(!mark[v]) {
par[v][0] = u;
par[v][1] = par[u][1] + 1;
DFS(v);
cnt[u] += cnt[v];
}
else if(par[u][0] == v)
multi ++;
else if(par[v][1] < par[u][1]) {
cnt[u] ++;
cnt[v] --;
}
}
if(multi == 1 && !cnt[u])
cout << u << " " << par[u][0] << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1 ; i <= n ; i ++)
par[i][0] = par[i][1] = i , sz[i][0] = sz[i][1] = 1;
for(int i = 0 ; i < m ; i ++) {
int u , v;
cin >> u >> v;
merge(u , v);
}
ms(par , 0);
for(int i = 1 ; i <= n ; i ++) {
if(!mark[i]) {
DFS(i);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3796 KB |
Output is correct |
2 |
Correct |
4 ms |
3668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
3888 KB |
Output is correct |
2 |
Correct |
85 ms |
3628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
4364 KB |
Output is correct |
2 |
Correct |
160 ms |
3980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
5708 KB |
Output is correct |
2 |
Correct |
190 ms |
5504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
10556 KB |
Output is correct |
2 |
Correct |
261 ms |
7472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
11572 KB |
Output is correct |
2 |
Correct |
445 ms |
9032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
615 ms |
13332 KB |
Output is correct |
2 |
Correct |
569 ms |
9404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
773 ms |
13388 KB |
Output is correct |
2 |
Correct |
715 ms |
9276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
905 ms |
12904 KB |
Output is correct |
2 |
Runtime error |
929 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |