이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back
#define EP emplace_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int N = 5e5 + 7;
int n, m, ptr;
bool vis[N], seen[N];
int cnt[N];
VPII adj[N];
VI ans[N];
struct Tour {
bool vis[N];
VI ord;
void add(int x) {
if (vis[x]) {
int now = ord.back();
while(now != x) {
ans[ptr].PB(now);
vis[now] = 0;
ord.pop_back();
now = ord.back();
}
ans[ptr].PB(now);
vis[now] = 0;
ord.pop_back();
ptr++;
}
vis[x] = 1;
ord.PB(x);
return;
}
} etds;
void init() {
cin >> n >> m;
F0R(i, m) {
int u, v;
cin >> u >> v;
adj[--u].PB({--v, i});
adj[v].PB({u, i});
}
return;
}
void dfs(int now) {
vis[now] = 1;
//cout << "now on : " << now + 1 << endl;
while(cnt[now] < adj[now].size()) {
cnt[now]++;
if (!seen[adj[now][ cnt[now] - 1 ].S]) {
seen[adj[now][ cnt[now] - 1 ].S] = 1;
dfs(adj[now][ cnt[now] - 1 ].F);
}
}
etds.add(now);
return;
}
int main() {
IOS;
init();
F0R(i, n) if (!vis[i]) dfs(i);
F0R(i, ptr) {
for(int on : ans[i]) cout << on + 1 << ' ';
cout << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'void dfs(int)':
postmen.cpp:83:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | while(cnt[now] < adj[now].size()) {
| ~~~~~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |