이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MAXBUF = (1 << 17);
char buf[MAXBUF];
int pbuf = MAXBUF;
inline int getnr() {
char ch = fgetc(stdin);
while(!isdigit(ch)) {
ch = fgetc(stdin);
}
int nr = 0;
while(isdigit(ch)) {
nr = nr * 10 + ch - '0';
ch = fgetc(stdin);
}
return nr;
}
const int MAXN = (int) 5e5;
vector <int> g[MAXN + 1];
pair <int, int> edges[MAXN + 1];
bool vis[MAXN + 1], vis1[MAXN + 1];
int ord[MAXN + 1], sz;
void dfs(int nod) {
while(g[nod].size()) {
auto it = g[nod].back();
g[nod].pop_back();
if(vis[it] == 0) {
vis[it] = 1;
dfs(edges[it].first ^ edges[it].second ^ nod);
}
}
ord[sz++] = nod;
}
int stk[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m;
//ios::sync_with_stdio(false);
//cin.tie(0), cout.tie(0);
n = getnr();
m = getnr();
for(i = 1; i <= m; i++) {
int x, y;
x = getnr();
y = getnr();
edges[i] = {x, y};
g[x].push_back(i);
g[y].push_back(i);
}
dfs(1);
int sz1 = 0;
for(i = 0; i < sz; i++) {
if(vis1[ord[i]] == 0) {
vis1[ord[i]] = 1;
stk[++sz1] = ord[i];
}
else {
while(stk[sz1] != ord[i]) {
printf("%d " ,stk[sz1]);
vis1[stk[sz1]] = 0;
sz1--;
}
printf("%d\n" ,ord[i]);
}
}
//cout << ans;
//cin.close();
//cout.close();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'int main()':
postmen.cpp:52:12: warning: variable 'n' set but not used [-Wunused-but-set-variable]
int i, n, m;
^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |