# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
669604 |
2022-12-06T20:16:17 Z |
radinr85 |
Pipes (CEOI15_pipes) |
C++17 |
|
5000 ms |
20036 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 cnt[N];
int n , m;
int get_par(int u , int x) {
while(par[u][x] != u) {
u = par[u][x];
}
return u;
}
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) {
ver[u].pb(v);
ver[v].pb(u);
par[u][1] = v;
}
}
else {
ver[u].pb(v);
ver[v].pb(u);
par[u][0] = v;
}
}
int 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;
cnt[u] += DFS(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;
return cnt[u];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
for(int i = 0 ; i < N ; i ++)
par[i][0] = par[i][1] = i;
cin >> n >> m;
for(int i = 0 ; i < m ; i ++) {
int u , v;
cin >> u >> v;
merge(u , v);
}
for(int i = 1 ; i <= n ; i ++) {
if(!mark[i]) {
par[i][0] = 0;
par[i][1] = 0;
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 |
5 ms |
3924 KB |
Output is correct |
2 |
Correct |
5 ms |
3640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
482 ms |
4292 KB |
Output is correct |
2 |
Correct |
240 ms |
3816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1332 ms |
5700 KB |
Output is correct |
2 |
Correct |
827 ms |
4804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3290 ms |
8912 KB |
Output is correct |
2 |
Correct |
2794 ms |
7272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5052 ms |
15012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5047 ms |
16924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5019 ms |
20036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5065 ms |
19928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5049 ms |
18800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |