Submission #98420

#TimeUsernameProblemLanguageResultExecution timeMemory
98420KastandaSenior Postmen (BOI14_postmen)C++11
55 / 100
609 ms42912 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, cyc, from[N], to[N], M[N], S[N], ri[N];
int ts, st[N];
vector < int > Adj[N];
/*void DFS(int v)
{
    S[v] = 1;
    #define id (Adj[v][ri[v]])
    #define u (from[id] ^ to[id] ^ v)
    while (ri[v])
    {
        ri[v] --;
        //int id = Adj[v][ri[v]];
        if (M[id]) continue;
        M[id] = 1;
        //int u = from[id] ^ to[id] ^ v;
        if (S[u])
        {
            cyc = u; S[v] = 0;
            printf("%d", v);
            return ;
        }
        DFS(u);
        if (cyc)
            printf(" %d", v);
        if (cyc != v)
        {
            S[v] = 0;
            return ;
        }
        else
            cyc = 0, printf("\n");
    }
    #undef id
    #undef u
    S[v] = 0;
}*/
int v, u, id;
inline void DFS()
{
    ts = 0;
    st[++ ts] = v;
    while (ts)
    {
        v = st[ts];
        S[v] = 1;
        while (ri[v] < (int)Adj[v].size())
        {
            id = (Adj[v][ri[v]]);
            ri[v] ++;
            u = (from[id] ^ to[id] ^ v);
            if (M[id]) continue;
            M[id] = 1;
            if (S[u])
            {
                while (st[ts] != u)
                {
                    printf("%d ", st[ts]);
                    S[st[ts]] = 0; ts --;
                }
                printf("%d\n", u);
                ts ++;
                break;
            }
            st[++ ts] = u;
            ts ++;
            break;
        }
        ts --;
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
    {
        scanf("%d%d", &from[i], &to[i]);
        Adj[from[i]].push_back(i);
        Adj[to[i]].push_back(i);
    }
    for (int i = 1; i <= n; i++)
        ri[i] = 0;
    for (int i = 1; i <= n; i++)
        v = i, DFS();
    return 0;
}

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:76: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:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &from[i], &to[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...