Submission #11585

# Submission time Handle Problem Language Result Execution time Memory
11585 2014-12-02T15:54:43 Z gs14004 Senior Postmen (BOI14_postmen) C++
0 / 100
5 ms 432 KB
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
 
int n,m;
int st[1000005], con[1000005], link[1000005], v[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];
        if(p&1) v[p+1]=1;
        else v[p-1]=1;
        if(!v[p]) f(pos);
        p = con[p];
    }
    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:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<cyc.size(); i++) {
                   ~^~~~~~~~~~~
postmen.cpp:33: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:36: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 Correct 4 ms 384 KB Output is correct
2 Incorrect 5 ms 432 KB Edge does not exist or used 6, 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Edge does not exist or used 6, 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Edge does not exist or used 6, 1
3 Halted 0 ms 0 KB -