Submission #244478

# Submission time Handle Problem Language Result Execution time Memory
244478 2020-07-04T06:48:54 Z dwsc Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
24 ms 2544 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n,m;
vector<int> adj[1010];
int depth[1010],p[1010][11];
int lowest[1010][11];
int relabel[1010];
int counter;
void dfs(int u,int pa){
    //cout << u << pa << "hi\n";
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i];
        if (p[v][0] == 0){
            p[v][0] = u;
            depth[v] = depth[u]+1;
            dfs(v,u);
        }
    }
    relabel[u] = ++counter;
}
int lowestjump[1010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for (int i = 1; i <= n; i++){
        if (p[i][0] == 0) {
            p[i][0] = -1;
            dfs(i,-1);
        }
    }
    vector<ii> backedges;
    for (int i = 1; i <= n; i++){
        //cout << p[i][0] << "\n";
        lowestjump[i] = 1e9;
        for (int j = 0; j < adj[i].size(); j++){
            int ni = adj[i][j];
            if (p[ni][0] == i || p[i][0] == ni) continue;
            if (depth[i] < depth[ni]) continue;
            lowestjump[i] = min(lowestjump[i],relabel[ni]);
            if (depth[i]-depth[ni] >= 3) backedges.push_back(ii(i,ni));
        }
    }
    for (int i = 0; i < backedges.size(); i++){
        int minjump = 1e9;
        int start = backedges[i].first, fin = backedges[i].second;
        if (lowestjump[start] != relabel[fin]) continue;
        int temp = start;
        int counting = 0;
        while (temp != fin){
            counting++;
            if (counting > 1000) cout << 1/0;
            temp = p[temp][0];
            minjump = min(minjump,lowestjump[temp]);
        }
        if (minjump <= relabel[fin]) continue;
        cout << start << " ";
        while (start != fin){
            start = p[start][0];
            cout << start << " ";
        }
        return 0;
    }
    cout << "no";
    return 0;
}

Compilation message

indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:12:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adj[u].size(); i++){
                     ~~^~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:43:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < adj[i].size(); j++){
                         ~~^~~~~~~~~~~~~~~
indcyc.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < backedges.size(); i++){
                     ~~^~~~~~~~~~~~~~~~~~
indcyc.cpp:59:43: warning: division by zero [-Wdiv-by-zero]
             if (counting > 1000) cout << 1/0;
                                          ~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Expected integer, but "no" found
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Incorrect 5 ms 512 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 512 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 1664 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1152 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2544 KB Output is correct
2 Correct 24 ms 2544 KB Output is correct
3 Incorrect 18 ms 1788 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -