#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+3;
int i,j,p,q,n,m,k;
int used[maxn],uk[maxn],came[maxn],usedge[maxn];
vector <pair <int,int>> v[maxn];
vector <vector <int>> ans;
void dfs(int u)
{
if(used[u]){
while(used[u])
{
cout<<u<<" ";
used[u] = 0;
u = came[u];
}
cout<<endl;
}
while(uk[u]<v[u].size())
{
q = v[u][uk[u]].second;
int edge = v[u][uk[u]].first;
uk[u]++;
if(!usedge[edge])
{
usedge[edge] = true;
used[u] = 1;
came[q] = u;
dfs(q);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>p>>q;
v[p].push_back({i,q});
v[q].push_back({i,p});
}
dfs(1);
return 0;
}
Compilation message
postmen.cpp: In function 'void dfs(int)':
postmen.cpp:19:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while(uk[u]<v[u].size())
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Incorrect |
4 ms |
14940 KB |
Edge does not exist or used 1, 3 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
4 ms |
15004 KB |
Edge does not exist or used 1, 3 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
4 ms |
14940 KB |
Edge does not exist or used 1, 3 |
3 |
Halted |
0 ms |
0 KB |
- |