Submission #44770

# Submission time Handle Problem Language Result Execution time Memory
44770 2018-04-06T06:51:39 Z RayaBurong25_1 Potemkin cycle (CEOI15_indcyc) C++17
40 / 100
1000 ms 1560 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)
{
    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;
    for (i = 0; i < s; i++)
    {
        v = AdjList[u][i];
        if (!Vis[v])
        {
            dfs(r, v, u);
        }
    }
    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:62:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < Ans.size(); i++)
                     ~~^~~~~~~~~~~~
indcyc.cpp:48: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:52: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 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 516 KB Output is correct
2 Correct 2 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 568 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 177 ms 576 KB Output is correct
2 Correct 121 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 1168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 1168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 1560 KB Time limit exceeded
2 Halted 0 ms 0 KB -