제출 #11580

#제출 시각아이디문제언어결과실행 시간메모리
11580gs14004어르신 집배원 (BOI14_postmen)C++98
38 / 100
1096 ms44576 KiB
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

struct edge{int pos, rev; };

vector<edge> graph[500005];
vector<bool> cant[500005];

int n,m;

vector<int> cyc, temp;

void add_edge(int s, int e){
    graph[s].push_back({e,(int)graph[e].size()});
    graph[e].push_back({s,(int)graph[s].size()-1});
    cant[s].push_back(0);
    cant[e].push_back(0);
}

void f(int x){
    for (int i=0; i<graph[x].size(); i++) {
        if(cant[x][i]) continue;
        cant[x][i] = 1;
        int pos = graph[x][i].pos;
        int rev = graph[x][i].rev;
        cant[pos][rev] = 1;
        f(pos);
    }
    cyc.push_back(x);
}

int vis[500005];
int main(){
    scanf("%d %d",&n,&m);
    for (int i=0; i<m; i++) {
        int s,e;
        scanf("%d %d",&s,&e);
        add_edge(s,e);
    }
    f(1);
    for (int i=0; i<cyc.size(); i++) {
        temp.push_back(cyc[i]);
        if(vis[cyc[i]]){
            printf("%d",temp.back());
            temp.pop_back();
            while(temp.back() != cyc[i]){
                printf(" %d",temp.back());
                vis[temp.back()] = 0;
                temp.pop_back();
                if(temp.back() == cyc[i]) printf("\n");
            }
        }
        else vis[cyc[i]] = 1;
    }
}

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

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