# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1035172 |
2024-07-26T05:30:14 Z |
vjudge1 |
Pipes (CEOI15_pipes) |
C++ |
|
768 ms |
55380 KB |
#pragma GCC optimize("O3,unroll-loops")
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e5+2;
namespace d1 {
int e[N];
int find(int &x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
};
namespace d2 {
int e[N];
int find(int &x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
};
vector<int> g[N];
int timer=0;
void dfs(int at, int par) {
d1::e[at]=d2::e[at]=++timer;
for(int to:g[at]) {
if(to == par) {
par+=N;
continue;
}
if(d2::e[to]) {
d1::e[at]=min(d1::e[at], d2::e[to]);
} else {
dfs(to, at);
d1::e[at]=min(d1::e[at], d1::e[to]);
}
}
if(par>N)par-=N;
if(d1::e[at] == d2::e[at] and at!=par) {
printf("%d %d\n", at, par);
}
}
int n, m, u, v;
int main() {
srand(time(0));
scanf("%d %d", &n, &m);
//nt u, v;
for(int i = 1;i<N;i++)d1::e[i]=d2::e[i]=-1;
for(int i = 0;i<m;i++) {
scanf("%d %d", &u, &v);
if((d1::join(u, v) || d2::join(u, v))) {
g[u].push_back(v);
g[v].push_back(u);
}
}
for(int i = 1;i<N;i++)d1::e[i]=d2::e[i]=0;
for(int i= 1;i<=n;i++) {
if(!d1::e[i]) {
dfs(i, i);
}
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d %d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3932 KB |
Output is correct |
2 |
Correct |
4 ms |
3768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
3704 KB |
Output is correct |
2 |
Correct |
68 ms |
3696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
4464 KB |
Output is correct |
2 |
Correct |
145 ms |
3928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
5864 KB |
Output is correct |
2 |
Runtime error |
170 ms |
18260 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
10228 KB |
Output is correct |
2 |
Runtime error |
244 ms |
23484 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
11384 KB |
Output is correct |
2 |
Runtime error |
421 ms |
38484 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
562 ms |
13204 KB |
Output is correct |
2 |
Runtime error |
531 ms |
45048 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
667 ms |
13136 KB |
Output is correct |
2 |
Runtime error |
642 ms |
55380 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
768 ms |
20144 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |