제출 #31553

#제출 시각아이디문제언어결과실행 시간메모리
31553Kanvie어르신 집배원 (BOI14_postmen)C++14
38 / 100
1087 ms16608 KiB
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> pii;
int n,m,vv,u,cnt,lol;
vector<pii>v[500001];
bool visit[500001],fi,edge[500001];
stack<int>s,ss;
inline bool chk(int x)
{
    if(!edge[x]){edge[x]=true;return true;}
    else return false;
}
void push_db(int x)
{
    if(!visit[x])
    {
        ss.push(x);
        visit[x]=true;
        return;
    }
    else
    {
        if(fi)printf("\n");
        else fi=true;
        while(1)
        {
            lol=ss.top();
            if(lol!=x)printf("%d ",lol);
            else printf("%d",lol);
            if(lol!=x){visit[lol]=false;ss.pop();}
            else break;
        }
    }
}
int x,y;
int main()
{
    ios_base::sync_with_stdio(false);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&x,&y);
        ++cnt;
        v[x].push_back({y,cnt});
        v[y].push_back({x,cnt});
    }
    s.push(1);
    fi=false;
    while(!s.empty())
    {
        u=s.top();
        for(int i=0;i<v[u].size();++i)
        {
            vv=v[u][i].fi;
            if(chk(v[u][i].se))break;
            if(i==v[u].size()-1)vv=-1;
        }
        if(vv!=-1)s.push(vv);
        else {s.pop();push_db(u);}
    }
}

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

postmen.cpp: In function 'int main()':
postmen.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<v[u].size();++i)
                     ~^~~~~~~~~~~~
postmen.cpp:58:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(i==v[u].size()-1)vv=-1;
                ~^~~~~~~~~~~~~~~
postmen.cpp:41: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:44: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...