Submission #44776

# Submission time Handle Problem Language Result Execution time Memory
44776 2018-04-06T07:20:31 Z RayaBurong25_1 Potemkin cycle (CEOI15_indcyc) C++17
50 / 100
1000 ms 1516 KB
#include <stdio.h>
#include <vector>
std::vector<int> AdjList[1005];
std::vector<int> Path;
std::vector<int> Ans;
int Vis[1005];
void dfs(int r, int u, int pa)
{
    if (Ans.size() > 0)
        return;
    Vis[u] = 1;
    Path.push_back(u);
    int i, v, s = AdjList[u].size();
    int ok = Path.size() >= 4, toRoot = 0;
    for (i = 0; i < s; i++)
    {
        v = AdjList[u][i];
        if (Vis[v] && v != pa)
        {
            if (v == r && Path.size() >= 4)
            {
                toRoot = 1;
                // Ans = Path;
            }
            else
            {
                ok = 0;
                Path.pop_back();
                Vis[u] = 0;
                return;
            }
        }
    }
    if (ok && toRoot)
    {
        Ans = Path;
        return;
    }
    else if (toRoot)
    {
        Path.pop_back();
        Vis[u] = 0;
        return;
    }
    for (i = 0; i < s; i++)
    {
        v = AdjList[u][i];
        if (!Vis[v])
        {
            dfs(r, v, u);
            if (Ans.size() > 0)
                return;
        }
    }
    Path.pop_back();
    Vis[u] = 0;
}
int main()
{
    int N, R;
    scanf("%d %d", &N, &R);
    int i, u, v;
    for (i = 0; i < R; i++)
    {
        scanf("%d %d", &u, &v);
        AdjList[u].push_back(v);
        AdjList[v].push_back(u);
    }
    for (i = 1; i <= N; i++)
    {
        dfs(i, i, 0);
    }
    if (Ans.size() > 0)
    {
        for (i = 0; i < Ans.size(); i++)
            printf("%d ", Ans[i]);
    }
    else
        printf("no");
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:75:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < Ans.size(); i++)
                     ~~^~~~~~~~~~~~
indcyc.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &R);
     ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
# 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 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 564 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 564 KB Output is correct
2 Correct 120 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 248 ms 712 KB Output is correct
2 Execution timed out 1079 ms 720 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 1128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 1128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 1516 KB Time limit exceeded
2 Halted 0 ms 0 KB -