이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* powered by ANDRIY POPYK
* in honor of SEGMENT DECOMPOSITION and N ^ (log(N)) and hate_club_Dasha_Lobas
* I hate GeZhiyuan
* fuck you
*/
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3,sse4,popcnt")
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <string>
#include <vector>
#include <stack>
#include <random>
#include <ctime>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int mod = 998244353;
int inf = 2000000000;
vector <vector <int>> g;
vector <pair <int, int>> edges;
vector <int> ind_ed;
vector <bool> t;
vector <int> el;
void dfs(int ind)
{
while (ind_ed[ind] < g[ind].size())
{
int i = g[ind][ind_ed[ind]];
ind_ed[ind]++;
if (t[i] == true)
continue;
t[i] = true;
t[i ^ 1] = true;
dfs(edges[i].second);
}
el.push_back(ind);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int times_ = 1;
//cin >> times_;
while (times_--)
{
int n, m;
cin >> n >> m;
g.resize(n);
ind_ed.resize(n, 0);
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
u--;
v--;
g[u].push_back(2 * i);
g[v].push_back(2 * i + 1);
edges.push_back({ u , v });
edges.push_back({ v , u });
}
t.resize(edges.size(), false);
dfs(0);
vector <int> s(n+10);
vector <int> go_to(el.size(), inf);
for (int i = 0; i < el.size(); i++)
{
if (s[el[i]] == 0)
{
s[el[i]]++;
}
else
{
int ind = i - 1;
while (s[el[i]] > 0)
{
if (s[el[ind]] > 0)
cout << el[ind] + 1 << " ";
s[el[ind]]--;
ind--;
if (ind < 0)
break;
ind = min(ind, go_to[ind]);
if (ind < 0)
break;
}
go_to[i - 1] = ind;
cout << "\n";
s[el[i]]++;
}
}
}
}
/*
axbbbbbbzbxbbabaxbbabababababababaababababababababaabababababababxbxbb
5
ababb
bbb
tr
are
aaa
*/
/*
4
12
1 1 1 2 2 3 4 4 7 7 6
11 2 1 11 12 8 5 8 8 5 11 7
13
1 1 1 2 2 2 3 3 4 5 6 6
2 2 2 1 4 9 7 2 5 2 1 11 2
7
1 1 2 2 3 3
6 5 2 3 6 5 6
*/
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'void dfs(int)':
postmen.cpp:48:21: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | while (ind_ed[ind] < g[ind].size())
postmen.cpp: In function 'int main()':
postmen.cpp:100:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int i = 0; i < el.size(); i++)
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |