Submission #11584

# Submission time Handle Problem Language Result Execution time Memory
11584 2014-12-02T15:36:27 Z gs14004 Senior Postmen (BOI14_postmen) C++
0 / 100
5 ms 384 KB
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

int n,m;
int st[1000005], con[1000005], link[1000005], sz;

vector<int> cyc, temp;

void add_edge(int s, int e){
    sz++;
    link[sz] = e; con[sz] = st[s]; st[s] = sz;
    sz++;
    link[sz] = s; con[sz] = st[e]; st[e] = sz;
}

void f(int x){
    int p = st[x];
    while (p) {
        int pos = link[p];
        st[pos] = con[st[pos]];
        p = con[p];
        f(pos);
    }
    st[x] = 0;
    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;
    }
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:39:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<cyc.size(); i++) {
                   ~^~~~~~~~~~~
postmen.cpp:32: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:35: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 time Memory Grader output
1 Incorrect 5 ms 384 KB Edge does not exist or used 2, 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 360 KB Edge does not exist or used 2, 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 288 KB Edge does not exist or used 2, 3
2 Halted 0 ms 0 KB -