Submission #95853

# Submission time Handle Problem Language Result Execution time Memory
95853 2019-02-03T07:26:36 Z Kastanda Potemkin cycle (CEOI15_indcyc) C++11
90 / 100
1000 ms 1404 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1009;
int n, m, qu[N], P[N];
bitset < N > M, S, is[N];
vector < int > Adj[N];
inline void Prnt(int fxd, int v, int u)
{
    M = S = 0;
    memset(P, 0, sizeof(P));
    for (int &w : Adj[fxd])
        M[w] = 1;
    int l = 0, r = 0;
    qu[r ++] = v;
    S[v] = 1;
    while (r - l)
    {
        int nw = qu[l ++];
        for (int &w : Adj[nw])
            if (w != fxd && !S[w] && !(M[nw] && M[w]))
            {
                S[w] = 1;
                P[w] = nw;
                if (!M[w])
                    qu[r ++] = w;
            }
    }
    if (P[u] == 0)
        return ;
    vector < int > A;
    A.push_back(fxd);
    for (; u; u = P[u])
        A.push_back(u);
    for (int i = 0; i < (int)A.size(); i++)
        for (int j = i + 2; j < (int)A.size(); j++)
            if ((i != 0 || j != (int)A.size() - 1) && is[A[i]][A[j]])
                assert(0);
    for (int a : A)
        printf("%d ", a);
    printf("\n");
    exit(0);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[v].push_back(u);
        Adj[u].push_back(v);
        is[v][u] = is[u][v] = 1;
    }
    for (int fxd = 1; fxd <= n; fxd ++)
    {
        M = S = 0;
        for (int &v : Adj[fxd])
            M[v] = 1;
        for (int &v : Adj[fxd])
        {
            int l = 0, r = 0;
            qu[r ++] = v;
            vector < int > A = {v};
            S[v] = 1;
            while (r - l)
            {
                int u = qu[l ++];
                for (int &w : Adj[u])
                    if (w != fxd && !S[w] && !(M[u] && M[w]))
                    {
                        S[w] = 1;
                        if (M[w])
                            A.push_back(w);
                        else
                            qu[r ++] = w;
                    }
            }
            for (int i = 0; i < (int)A.size(); i++)
                for (int j = i + 1; j < (int)A.size(); j++)
                    if (!is[A[i]][A[j]])
                        Prnt(fxd, A[i], A[j]);
        }
    }
    return !printf("no\n");
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
indcyc.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 13 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 47 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1016 KB Output is correct
2 Correct 10 ms 760 KB Output is correct
3 Correct 207 ms 1056 KB Output is correct
4 Correct 99 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 764 KB Output is correct
2 Execution timed out 1079 ms 760 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1400 KB Output is correct
2 Correct 202 ms 1404 KB Output is correct
3 Correct 23 ms 1272 KB Output is correct
4 Correct 401 ms 1276 KB Output is correct