Submission #46928

# Submission time Handle Problem Language Result Execution time Memory
46928 2018-04-24T22:05:13 Z alex99 Potemkin cycle (CEOI15_indcyc) C++14
100 / 100
296 ms 5664 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int N, M;
vector <int> G[1005];
bool X[1005][1005];
pair <int, int> E[100005];
bool Blocked[1005];
vector <int> V;
bool Use[1005];
int TT[1005];
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
        //E[i] = make_pair(x, y);
        X[x][y] = X[y][x] = 1;
    }
    for(int i = 1; i <= N; i++)
        X[i][i] = 1;
}
void DFS(int node, int org)
{
    Use[node] = 1;
    if(X[node][org] == 1)
    {
        V.push_back(node);
        return;
    }
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        if(Use[neighb] == 0)
        {
            DFS(neighb, org);
        }
    }
}
void BFS(int x, int y, int v)
{
    queue <int> Q;
    for(int i = 1; i <= N; i++)
        Use[i] = 0;
    Q.push(x);
    Use[x] = 1;
    while(!Q.empty())
    {
        int node = Q.front();
        Q.pop();
        for(int i = 0; i < G[node].size(); i++)
        {
            int neighb = G[node][i];
            if(Use[neighb] == 0 && (neighb == y || X[neighb][v] == 0))
            {
                TT[neighb] = node;
                Use[neighb] = 1;
                Q.push(neighb);
            }
        }
    }
    int node = y;
    while(node != 0)
    {
        cout << node << " ";
        node = TT[node];
    }
    cout << v << "\n";
}
void Solve()
{
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++)
            Use[j] = 0;
        for(int j = 1; j <= N; j++)
        {
            if(X[i][j] == 0 && Use[j] == 0 && i != j)
            {
                V.clear();
                DFS(j, i);
                for(int k = 0; k < V.size(); k++)
                    for(int p = k + 1; p < V.size(); p++)
                        if(X[V[k]][V[p]] == 0)
                        {
                            BFS(V[k], V[p], i);
                            return;
                        }
                for(int k = 0; k < V.size(); k++)
                    Use[V[k]] = 0;
            }
        }
    }
    cout << "no\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}

Compilation message

indcyc.cpp: In function 'void DFS(int, int)':
indcyc.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < G[node].size(); i++)
                    ~~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'void BFS(int, int, int)':
indcyc.cpp:56:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < G[node].size(); i++)
                        ~~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'void Solve()':
indcyc.cpp:87:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int k = 0; k < V.size(); k++)
                                ~~^~~~~~~~~~
indcyc.cpp:88:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for(int p = k + 1; p < V.size(); p++)
                                        ~~^~~~~~~~~~
indcyc.cpp:94:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int k = 0; k < V.size(); k++)
                                ~~^~~~~~~~~~
# 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 544 KB Output is correct
4 Correct 2 ms 656 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 784 KB Output is correct
2 Correct 3 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1156 KB Output is correct
2 Correct 4 ms 1196 KB Output is correct
3 Correct 5 ms 1220 KB Output is correct
4 Correct 13 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1280 KB Output is correct
2 Correct 8 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2912 KB Output is correct
2 Correct 17 ms 2912 KB Output is correct
3 Correct 296 ms 3412 KB Output is correct
4 Correct 133 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3416 KB Output is correct
2 Correct 107 ms 3568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 4360 KB Output is correct
2 Correct 55 ms 4900 KB Output is correct
3 Correct 46 ms 5276 KB Output is correct
4 Correct 255 ms 5664 KB Output is correct