# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
540705 |
2022-03-21T12:47:30 Z |
Vladth11 |
Pipes (CEOI15_pipes) |
C++14 |
|
969 ms |
13076 KB |
#include <iostream>
#include <vector>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 100001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 1000000;
const ll nr_of_bits = 16;
vector <int> v[NMAX];
int root;
int dp[NMAX], lvl[NMAX];
int parent[NMAX];
int parentB[NMAX];
int findR(int a){
if(parent[a] == a)
return a;
return parent[a] = findR(parent[a]);
}
int findRB(int a){
if(parentB[a] == a)
return a;
return parentB[a] = findRB(parentB[a]);
}
void unite(int a, int b){
a = findR(a);
b = findR(b);
parent[a] = b;
}
void uniteB(int a, int b){
a = findRB(a);
b = findRB(b);
parentB[a] = b;
}
void DFS(int node, int p){
lvl[node] = lvl[p] + 1;
for(auto x : v[node]){
if(lvl[x] == 0){
DFS(x, node);
dp[node] += dp[x];
}else if(lvl[x] > lvl[node]){
dp[node]--;
}else{
dp[node]++;
}
}
if(node != root){
dp[node]--;
}
if(dp[node] == 0 && node != root){
cout << node << " " << p << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, i;
cin >> n >> m;
for(i = 1; i <= n; i++){
parent[i] = i;
parentB[i] = i;
}
for(i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
if(findR(a) != findR(b)){
v[a].push_back(b);
v[b].push_back(a);
unite(a, b);
}else if(findRB(a) != findRB(b)){
v[a].push_back(b);
v[b].push_back(a);
uniteB(a, b);
}
}
for(i = 1; i <= n; i++){
if(!lvl[i]){
root = i;
DFS(root, 0);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3248 KB |
Output is correct |
2 |
Correct |
6 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
3212 KB |
Output is correct |
2 |
Correct |
89 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
3896 KB |
Output is correct |
2 |
Correct |
185 ms |
3492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
242 ms |
5340 KB |
Output is correct |
2 |
Correct |
228 ms |
4916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
329 ms |
9964 KB |
Output is correct |
2 |
Correct |
284 ms |
7052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
493 ms |
11340 KB |
Output is correct |
2 |
Correct |
458 ms |
8560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
685 ms |
12944 KB |
Output is correct |
2 |
Correct |
645 ms |
8872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
819 ms |
13076 KB |
Output is correct |
2 |
Correct |
784 ms |
8872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
969 ms |
12692 KB |
Output is correct |
2 |
Correct |
881 ms |
10208 KB |
Output is correct |