제출 #129754

#제출 시각아이디문제언어결과실행 시간메모리
129754SamAnd어르신 집배원 (BOI14_postmen)C++17
55 / 100
653 ms94176 KiB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 500005;

int n, m;
set<int> a[N];

vector<int> v;
void dfs(int x)
{
    while (1)
    {
        if (a[x].empty())
            break;
        int h = *a[x].begin();
        a[x].erase(h);
        a[h].erase(x);
        dfs(h);
    }
    v.push_back(x);
}

bool c[N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        a[x].insert(y);
        a[y].insert(x);
    }
    dfs(1);
    stack<int> s;
    for (int i = 0; i < v.size(); ++i)
    {
        if (c[v[i]])
        {
            printf("%d ", v[i]);
            while (s.top() != v[i])
            {
                printf("%d ", s.top());
                c[s.top()] = false;
                s.pop();
            }
            printf("\n");
        }
        else
        {
            s.push(v[i]);
            c[v[i]] = true;
        }
    }
    return 0;
}

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

postmen.cpp: In function 'int main()':
postmen.cpp:37:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
postmen.cpp:27: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:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...