# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
88747 | popovicirobert | 어르신 집배원 (BOI14_postmen) | C++14 | 14 ms | 12136 KiB |
이 제출은 이전 버전의 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 char nextch() {
if(pbuf == MAXBUF) {
fread(buf, 1, MAXBUF, stdin);
pbuf = 0;
}
return buf[pbuf++];
}
inline int getnr() {
char ch = nextch();
while(!isdigit(ch)) {
ch = nextch();
}
int nr = 0;
while(isdigit(ch)) {
nr = nr * 10 + ch - '0';
ch = nextch();
}
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];
vector <int> ord;
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.push_back(nod);
}
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 sz = ord.size();
vector <int> stk;
for(i = 0; i < sz; i++) {
if(vis1[ord[i]] == 0) {
vis1[ord[i]] = 1;
stk.push_back(ord[i]);
}
else {
while(stk.back() != ord[i]) {
printf("%d " ,stk.back());
vis1[stk.back()] = 0;
stk.pop_back();
}
printf("%d " ,ord[i]);
}
}
//cout << ans;
//cin.close();
//cout.close();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |