# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100496 |
2019-03-11T19:21:43 Z |
doowey |
Pipes (CEOI15_pipes) |
C++14 |
|
1135 ms |
14840 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 9;
struct DSU{
int pi[N];
int sz[N];
int fin(int x){
if(pi[x] == x)
return x;
return pi[x] = fin(pi[x]);
}
bool unite(int a, int b){
a = fin(a);
b = fin(b);
if(a==b)
return false;
if(sz[a] > sz[b])
swap(a, b);
sz[b] += sz[a];
pi[a] = b;
return true;
}
void Init(){
for(int i = 0 ;i < N ; i ++ ){
pi[i] = i;
sz[i] = 1;
}
}
};
DSU A, B;
vector<int> T[N];
vector<pii> answ;
int tin[N];
int low[N];
int timer;
bool vis[N];
void bridge(int a, int b){
if(a>b)
swap(a, b);
answ.push_back(mp(a,b));
}
void dfs(int node, int par){
if(vis[node]){
return;
}
vis[node] = true;
tin[node] = timer ++ ;
low[node] = tin[node];
for(auto x : T[node]){
if(x == par){
continue;
}
if(vis[x]){
low[node] = min(low[node], tin[x]);
}
else{
dfs(x, node);
low[node] = min(low[node], low[x]);
if(tin[node] < low[x]){
bridge(node, x);
}
}
}
}
int main(){
fastIO;
A.Init();
B.Init();
int n, m;
cin >> n >> m;
int u, v;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
if(A.unite(u, v)){
T[u].push_back(v);
T[v].push_back(u);
}
else if(B.unite(u, v)){
T[u].push_back(v);
T[v].push_back(u);
}
}
for(int i = 1; i <= n; i ++ )
dfs(i,-1);
bool ok;
sort(answ.begin(), answ.end());
for(int i = 0 ;i < answ.size(); i ++ ){
ok = true;
if(i>0)
if(answ[i]==answ[i-1])ok = false;
if(i+1<answ.size())
if(answ[i]==answ[i+1])ok = false;
if(ok)
cout << answ[i].fi << " " << answ[i].se << "\n";
}
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:108:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ;i < answ.size(); i ++ ){
~~^~~~~~~~~~~~~
pipes.cpp:112:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i+1<answ.size())
~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4224 KB |
Output is correct |
2 |
Incorrect |
5 ms |
4224 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4780 KB |
Output is correct |
2 |
Incorrect |
9 ms |
4480 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
4572 KB |
Output is correct |
2 |
Incorrect |
96 ms |
4440 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
167 ms |
5332 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
6796 KB |
Output is correct |
2 |
Correct |
241 ms |
6444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
412 ms |
11768 KB |
Output is correct |
2 |
Incorrect |
335 ms |
8312 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
609 ms |
12920 KB |
Output is correct |
2 |
Incorrect |
588 ms |
9948 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
851 ms |
14840 KB |
Output is correct |
2 |
Incorrect |
729 ms |
9988 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1096 ms |
14836 KB |
Output is correct |
2 |
Incorrect |
929 ms |
9984 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1135 ms |
14332 KB |
Output is correct |
2 |
Correct |
1068 ms |
11484 KB |
Output is correct |