제출 #6160

#제출 시각아이디문제언어결과실행 시간메모리
6160ainta어르신 집배원 (BOI14_postmen)C++98
100 / 100
397 ms21344 KiB
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
int nxt[1000010], ed[1000010], num[500010];
int n, m, used[1000010], v[500010];
int st[500010];
void Do(int start){
    int top = 0, x, y;
    st[++top] = start;
    v[start] = true;
    while (1){
        while (top){
            while (used[num[st[top]]])num[st[top]] = nxt[num[st[top]]];
            if (!num[st[top]]){
                v[st[top]] = false;
                top--;
            }
            else break;
        }
        if (!top)break;
        x = st[top];
        y = ed[num[x]];
        used[num[x]] = used[num[x] ^ 1] = true;
        num[x] = nxt[num[st[top]]];
        if (v[y]){
         
            while (1){
                printf("%d", st[top]);
                if (st[top] == y)break;
              printf(" ");
                v[st[top]] = false;
                top--;
            }
            printf("\n");
            continue;
        }
        else{
            st[++top] = y;
            v[y] = true;
        }
    }
    v[start] = false;
}
int main()
{
    int i, a, b, cnt = 1;
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; i++){
        scanf("%d%d", &a, &b);
        ed[++cnt] = b; nxt[cnt] = num[a]; num[a] = cnt;
        ed[++cnt] = a; nxt[cnt] = num[b]; num[b] = cnt;
    }
    for (i = 1; i <= n; i++){
        Do(i);
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

postmen.cpp:1:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)
 
postmen.cpp: In function 'int main()':
postmen.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...