# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1115999 |
2024-11-21T07:30:41 Z |
vjudge1 |
Pipes (CEOI15_pipes) |
C++17 |
|
997 ms |
65536 KB |
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
int MOD = 998244353,inf = 2e18;
const int N = 1e5+50,Q = 2e5+50;
int dad[N],cur[N];
int d1[N],d2[N];
vi edges[N],newedges[N];
vi traverse;
struct DSU {
void bfs(int node) {
d1[node] = 0;
queue<int> q;
q.push(node);
while (!q.empty()) {
int f = q.front();
q.pop();
for (auto it : edges[f]) {
if (d1[cur[it]] == -1) {
d1[cur[it]] = d1[f]+1;
q.push(cur[it]);
}
}
}
}
void bfs2(int node) {
d2[node] = 0;
queue<int> q;
q.push(node);
while (!q.empty()) {
int f = q.front();
//cout << "REACH" sp f sp d2[f] << '\n';
traverse.push_back(f);
q.pop();
for (auto it : edges[f]) {
if (d2[cur[it]] == -1) {
d2[cur[it]] = d2[f]+1;
q.push(cur[it]);
}
}
}
}
int find(int x) {
if (x == dad[x]) return x;
return dad[x] = find(dad[x]);
}
void unite(int a,int b) {
int x = find(a),y = find(b);
if (x == y) {
bfs(a);
bfs2(b);
int dist = d1[b];
int newname = inf;
for (auto it : traverse) if (d1[it]+d2[it] == dist) newname = min(newname,cur[it]);
for (auto it : traverse) {
if (d1[it]+d2[it] != dist) continue;
cur[it] = newname;
for (auto itt : edges[it]) {
if (d1[itt]+d2[itt] != dist) newedges[newname].push_back(cur[itt]);
}
edges[it].clear();
}
for (auto it : traverse) d1[it] = d2[it] = -1;
edges[newname].swap(newedges[newname]);
traverse.clear();
newedges[newname].clear();
}
else {
dad[x] = y;
edges[a].push_back(b);
edges[b].push_back(a);
}
}
};
void solve() {
memset(d1,-1,sizeof d1);
memset(d2,-1,sizeof d2);
int n,m;
cin >> n >> m;
for (int i=1;i<=n;i++) dad[i] = i,cur[i] = i;
DSU dsu;
vector<pii> edg(m);
for (int i=0;i<m;i++) {
int a,b;
cin >> a >> b;
edg.push_back({a,b});
dsu.unite(cur[a],cur[b]);
}
for (auto it : edg) {
if (cur[it.ff] != cur[it.ss]) cout << it.ff sp it.ss << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message
pipes.cpp:13:27: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
13 | int MOD = 998244353,inf = 2e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5712 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
6224 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
178 ms |
21008 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
309 ms |
31364 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
480 ms |
46740 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
752 ms |
57364 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
997 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
27 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |