#include <iostream>
#include <vector>
#define DIM 100002
using namespace std;
int t[DIM],t2[DIM],viz[DIM];
vector <int> L[DIM];
int n,m,i,j,x,y;
int get_rad (int x){
while (t[x] > 0)
x = t[x];
int nr = x;
while (t[nr] > 0){
int aux = t[nr];
t[nr] = x;
nr = aux;
}
return x;
}
int get_rad2 (int x){
while (t2[x] > 0)
x = t2[x];
int nr = x;
while (t2[nr] > 0){
int aux = t2[nr];
t2[nr] = x;
nr = aux;
}
return x;
}
void dfs (int nod){
viz[nod] = 1;
for (int i=0;i<L[nod].size();i++){
int vecin = L[nod][i];
if (!viz[vecin]){
if (t2[nod] == -1 && t2[vecin] == -1)
cout<<nod<<" "<<vecin<<"\n";
dfs (vecin);
}}
}
int main (){
cin>>n>>m;
for (i=1;i<=n;i++)
t[i] = t2[i] = -1;
for (i=1;i<=m;i++){
cin>>x>>y;
int rx = get_rad (x), ry = get_rad(y);
if (rx != ry){
L[x].push_back(y);
L[y].push_back(x);
if (t[rx] < t[ry]){
t[rx] += t[ry];
t[ry] = rx;
} else {
t[ry] += t[rx];
t[rx] = ry;
}
} else {
/// nodurile se alfa deja in aceeasi multime si toate muchiile
/// de pe drumul de la x la y NU pot fi critice
/// oare merge daca fac din nou paduri pt nodurile astea?
int rx2 = get_rad2(x), ry2 = get_rad2(y);
if (rx2 != ry2){
if (t2[rx2] < t2[ry2]){
t2[rx2] += t2[ry2];
t2[ry2] = rx2;
} else {
t2[ry2] += t2[rx2];
t2[rx2] = ry2;
}}}}
for (i=1;i<=n;i++)
if (!viz[i])
dfs (i);
return 0;
}
Compilation message
pipes.cpp: In function 'void dfs(int)':
pipes.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<L[nod].size();i++){
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
2936 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
525 ms |
2808 KB |
Output is correct |
2 |
Incorrect |
512 ms |
2836 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
929 ms |
3100 KB |
Output is correct |
2 |
Incorrect |
1094 ms |
3088 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1560 ms |
3652 KB |
Output is correct |
2 |
Runtime error |
1338 ms |
18140 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1985 ms |
5724 KB |
Output is correct |
2 |
Runtime error |
1740 ms |
23876 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3167 ms |
6144 KB |
Output is correct |
2 |
Runtime error |
3189 ms |
40088 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4286 ms |
7004 KB |
Output is correct |
2 |
Runtime error |
3981 ms |
48224 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5034 ms |
6592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5005 ms |
6364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |