# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98420 | Kastanda | 어르신 집배원 (BOI14_postmen) | C++11 | 609 ms | 42912 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, cyc, from[N], to[N], M[N], S[N], ri[N];
int ts, st[N];
vector < int > Adj[N];
/*void DFS(int v)
{
S[v] = 1;
#define id (Adj[v][ri[v]])
#define u (from[id] ^ to[id] ^ v)
while (ri[v])
{
ri[v] --;
//int id = Adj[v][ri[v]];
if (M[id]) continue;
M[id] = 1;
//int u = from[id] ^ to[id] ^ v;
if (S[u])
{
cyc = u; S[v] = 0;
printf("%d", v);
return ;
}
DFS(u);
if (cyc)
printf(" %d", v);
if (cyc != v)
{
S[v] = 0;
return ;
}
else
cyc = 0, printf("\n");
}
#undef id
#undef u
S[v] = 0;
}*/
int v, u, id;
inline void DFS()
{
ts = 0;
st[++ ts] = v;
while (ts)
{
v = st[ts];
S[v] = 1;
while (ri[v] < (int)Adj[v].size())
{
id = (Adj[v][ri[v]]);
ri[v] ++;
u = (from[id] ^ to[id] ^ v);
if (M[id]) continue;
M[id] = 1;
if (S[u])
{
while (st[ts] != u)
{
printf("%d ", st[ts]);
S[st[ts]] = 0; ts --;
}
printf("%d\n", u);
ts ++;
break;
}
st[++ ts] = u;
ts ++;
break;
}
ts --;
}
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &from[i], &to[i]);
Adj[from[i]].push_back(i);
Adj[to[i]].push_back(i);
}
for (int i = 1; i <= n; i++)
ri[i] = 0;
for (int i = 1; i <= n; i++)
v = i, DFS();
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... |