답안 #244509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244509 2020-07-04T08:19:17 Z dwsc Potemkin cycle (CEOI15_indcyc) C++14
60 / 100
56 ms 5504 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n,m;
vector<int> adj[1010];
int mat[1010][1010];
int depth[1010],p[1010];
int relabel[1010];
int counter;
int visited[1010];
int rmap[1010];
int comp[1010];
void dfs(int u,int pa){
    visited[u] = 1;
    //cout << u << pa << "hi\n";
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i];
        if (!visited[v]){
            p[v] = u;
            depth[v] = depth[u]+1;
            visited[v] = 1;
            comp[v] = comp[u];
            dfs(v,u);
        }
    }
    relabel[u] = ++counter;
    rmap[relabel[u]] = u;
}
vector<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;
        mat[x][y] = mat[y][x] = 1;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int num = 0;
    for (int i = 1; i <= n; i++){
        if (!visited[i]){
            depth[i] = 1;
            p[i] = -1;
            comp[i] = num++;
            dfs(i,-1);
        }
    }
    for (int i = 1; i <= n; i++){
        if (p[i] != -1) assert(relabel[p[i]] > relabel[i]);
        for (int j = 0; j < adj[i].size(); j++){
            int ni = adj[i][j];
            if (p[ni] == i || p[i] == ni) continue;
            if (depth[i] < depth[ni]) continue;
            lowestjump[i].push_back(relabel[ni]);
        }
        lowestjump[i].push_back(relabel[p[i]]);
        sort(lowestjump[i].begin(),lowestjump[i].end());
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            if (i == j) continue;
            if (comp[i] != comp[j] || depth[i]-depth[j] < 3) continue;
            if (mat[i][j] && comp[i] == comp[j]){
                int start = i, fin = j;
                //cout << start << " " << fin << "\n";
                int counter = 1;
                int cur = start;
                vector<int> temp;
                temp.push_back(cur);
                while (relabel[cur] < relabel[fin]){
                    int relabelval = *(upper_bound(lowestjump[cur].begin(),lowestjump[cur].end(),relabel[fin])-1);
                    if (cur == start) relabelval = *(lower_bound(lowestjump[cur].begin(),lowestjump[cur].end(),relabel[fin])-1);
                    int pos = rmap[relabelval];
                    cur = pos;
                    temp.push_back(cur);
                    //start++;
                }
                if (cur != fin || temp.size() < 4) continue;
                for (int k = 0; k < temp.size(); k++) cout <<temp[k] << " ";
                return 0;
            }
        }
    }
    cout << "no";
    return 0;
}

Compilation message

indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:16: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:52:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < adj[i].size(); j++){
                         ~~^~~~~~~~~~~~~~~
indcyc.cpp:81:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int k = 0; k < temp.size(); k++) cout <<temp[k] << " ";
                                 ~~^~~~~~~~~~~~~
indcyc.cpp:68:21: warning: unused variable 'counter' [-Wunused-variable]
                 int counter = 1;
                     ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 432 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 768 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1664 KB Output is correct
2 Correct 7 ms 1664 KB Output is correct
3 Correct 7 ms 1664 KB Output is correct
4 Correct 8 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1664 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 5120 KB Output is correct
2 Correct 16 ms 4864 KB Output is correct
3 Correct 30 ms 5120 KB Output is correct
4 Correct 21 ms 4864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 4736 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 3584 KB Output is correct
2 Correct 56 ms 3576 KB Output is correct
3 Correct 36 ms 5504 KB Output is correct
4 Correct 38 ms 5504 KB Output is correct