/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 5e5 + 10;
struct edge
{
int ver, rev, type;
edge(int _ver, int _rev, int _type)
{
ver = _ver;
rev = _rev;
type = _type;
}
};
int n, m;
vector < edge > g[maxn];
void add_edge(int v, int u)
{
g[v].push_back(edge(u, g[u].size(), 0));
g[u].push_back(edge(v, g[v].size() - 1, 0));
}
int used[maxn], it[maxn];
vector < vector < int > > euler_tour(int v)
{
vector < int > path;
stack < int > st;
st.push(v);
while(!st.empty())
{
int cur = st.top();
while(it[cur] < g[cur].size() && g[cur][it[cur]].type == 1)
it[cur] ++;
if (it[cur] == g[cur].size())
{
st.pop();
path.push_back(cur);
}
else
{
st.push(g[cur][it[cur]].ver);
g[g[cur][it[cur]].ver][g[cur][it[cur]].rev].type = 1;
it[cur] ++;
}
}
vector < vector < int > > ans;
vector < int > cur_path;
for (int i = 0; i < path.size(); i ++)
{
int cur = path[i];
if (!used[cur])
{
cur_path.push_back(cur);
used[cur] = 1;
}
else
{
vector < int > last;
last.push_back(cur);
while(cur_path.back() != cur)
{
last.push_back(cur_path.back());
used[cur_path.back()] = 0;
cur_path.pop_back();
}
ans.push_back(last);
}
}
return ans;
}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= m; i ++)
{
int v, u;
cin >> v >> u;
add_edge(v, u);
}
int root = 1;
while(g[root].empty())
root ++;
vector < vector < int > > ans = euler_tour(root);
for (int i = 0; i < ans.size(); i ++)
{
for (int v : ans[i])
cout << v << " ";
cout << endl;
}
}
int main()
{
speed();
solve();
return 0;
}
Compilation message
postmen.cpp: In function 'std::vector<std::vector<int> > euler_tour(int)':
postmen.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | while(it[cur] < g[cur].size() && g[cur][it[cur]].type == 1)
| ~~~~~~~~^~~~~~~~~~~~~~~
postmen.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | if (it[cur] == g[cur].size())
| ~~~~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i < path.size(); i ++)
| ~~^~~~~~~~~~~~~
postmen.cpp: In function 'void solve()':
postmen.cpp:111:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for (int i = 0; i < ans.size(); i ++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12020 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
12400 KB |
Output is correct |
5 |
Correct |
8 ms |
12116 KB |
Output is correct |
6 |
Correct |
8 ms |
12264 KB |
Output is correct |
7 |
Correct |
13 ms |
12860 KB |
Output is correct |
8 |
Correct |
7 ms |
12116 KB |
Output is correct |
9 |
Correct |
35 ms |
15840 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
7 ms |
12180 KB |
Output is correct |
12 |
Correct |
41 ms |
16208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12048 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
12244 KB |
Output is correct |
5 |
Correct |
7 ms |
12168 KB |
Output is correct |
6 |
Correct |
7 ms |
12276 KB |
Output is correct |
7 |
Correct |
11 ms |
12884 KB |
Output is correct |
8 |
Correct |
7 ms |
12116 KB |
Output is correct |
9 |
Correct |
37 ms |
15828 KB |
Output is correct |
10 |
Correct |
8 ms |
12244 KB |
Output is correct |
11 |
Correct |
7 ms |
12244 KB |
Output is correct |
12 |
Correct |
36 ms |
16268 KB |
Output is correct |
13 |
Correct |
50 ms |
18156 KB |
Output is correct |
14 |
Correct |
49 ms |
17940 KB |
Output is correct |
15 |
Correct |
49 ms |
19192 KB |
Output is correct |
16 |
Correct |
48 ms |
18156 KB |
Output is correct |
17 |
Correct |
54 ms |
18684 KB |
Output is correct |
18 |
Correct |
50 ms |
18020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
8 ms |
12240 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Correct |
10 ms |
12244 KB |
Output is correct |
7 |
Correct |
11 ms |
12964 KB |
Output is correct |
8 |
Correct |
7 ms |
12116 KB |
Output is correct |
9 |
Correct |
41 ms |
15856 KB |
Output is correct |
10 |
Correct |
7 ms |
12244 KB |
Output is correct |
11 |
Correct |
8 ms |
12212 KB |
Output is correct |
12 |
Correct |
37 ms |
16292 KB |
Output is correct |
13 |
Correct |
78 ms |
18120 KB |
Output is correct |
14 |
Correct |
49 ms |
17952 KB |
Output is correct |
15 |
Correct |
74 ms |
19196 KB |
Output is correct |
16 |
Correct |
55 ms |
18140 KB |
Output is correct |
17 |
Correct |
53 ms |
18752 KB |
Output is correct |
18 |
Correct |
75 ms |
18060 KB |
Output is correct |
19 |
Correct |
363 ms |
42448 KB |
Output is correct |
20 |
Correct |
374 ms |
48584 KB |
Output is correct |
21 |
Correct |
346 ms |
49848 KB |
Output is correct |
22 |
Correct |
372 ms |
49076 KB |
Output is correct |
23 |
Correct |
138 ms |
32428 KB |
Output is correct |
24 |
Correct |
401 ms |
49556 KB |
Output is correct |
25 |
Correct |
358 ms |
48880 KB |
Output is correct |