# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
658182 |
2022-11-12T10:50:09 Z |
blaze21 |
Pipes (CEOI15_pipes) |
C++17 |
|
1352 ms |
15384 KB |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <cassert>
#include <iomanip>
using namespace std;
#define pi pair<int, int>
#define f first
#define s second
vector <vector <int> > edges (1e5 + 5);
bool visited [(int)1e5 + 5];
int tin [(int)1e5 + 5], low [(int)1e5 + 5];
int timer = 0;
void dfs(int v, int prev){
visited[v] = true;
tin[v] = low[v] = timer++;
bool ok = false;
for(int u : edges[v]){
if(u == prev && !ok){
ok = true;
continue;
}
if(visited[u]){
low[v] = min(low[v], tin[u]);
}
else{
dfs(u, v);
low[v] = min(low[v], low[u]);
}
}
if(prev != -1 && tin[v] == low[v]){
cout << prev << " " << v << endl;
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, m;
cin >> n >> m;
vector <int> links1 (n + 1), links2 (n + 1), sz1 (n + 1, 1), sz2 (n + 1, 1);
iota(links1.begin(), links1.end(), 0);
iota(links2.begin(), links2.end(), 0);
while(m--){
int a, b, a1, b1, a2, b2;
cin >> a >> b;
a1 = a2 = a;
b1 = b2 = b;
while(a1 != links1[a1]){
a1 = links1[a1];
}
while(b1 != links1[b1]){
b1 = links1[b1];
}
while(a2 != links2[a2]){
a2 = links2[a2];
}
while(b2 != links2[b2]){
b2 = links2[b2];
}
if(a1 != b1){
edges[a].push_back(b);
edges[b].push_back(a);
if(sz1[a1] < sz1[b1]){
swap(a1, b1);
}
links1[b1] = a1;
sz1[a1] += sz1[b1];
}
else if(a2 != b2){
edges[a].push_back(b);
edges[b].push_back(a);
if(sz2[a2] < sz2[b2]){
swap(a2, b2);
}
links2[b2] = a2;
sz2[a2] += sz2[b2];
}
}
for(int i = 1; i <= n; i++){
if(!visited[i]){
dfs(i, -1);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3156 KB |
Output is correct |
2 |
Correct |
5 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
3000 KB |
Output is correct |
2 |
Correct |
114 ms |
2868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
3724 KB |
Output is correct |
2 |
Correct |
238 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
5268 KB |
Output is correct |
2 |
Correct |
280 ms |
5020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
10548 KB |
Output is correct |
2 |
Correct |
397 ms |
7604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
727 ms |
11668 KB |
Output is correct |
2 |
Correct |
623 ms |
9192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
887 ms |
13864 KB |
Output is correct |
2 |
Correct |
902 ms |
12860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1142 ms |
13864 KB |
Output is correct |
2 |
Correct |
1080 ms |
13644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1352 ms |
13316 KB |
Output is correct |
2 |
Correct |
1325 ms |
15384 KB |
Output is correct |