답안 #598867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598867 2022-07-19T06:39:55 Z 박상훈(#8456) Potemkin cycle (CEOI15_indcyc) C++17
60 / 100
1000 ms 6736 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
vector<int> adj[1010];
int n, no[1010][1010], pa[1010], subtree[1010];
bool visited[1010];

void getans(int R, int s, int e){
    //printf("%d %d %d: ", R, s, e);

    vector<int> ans1, ans2;
    for (;s!=R;s=pa[s]) ans1.push_back(s);
    for (;e!=R;e=pa[e]) ans2.push_back(e);
    reverse(ans2.begin(), ans2.end());

    for (auto &x:ans1) printf("%d ", x);
    printf("%d ", R);
    for (auto &x:ans2) printf("%d ", x);
    exit(0);
}

void bfs(int s){
    fill(pa+1, pa+n+1, 0);
    fill(subtree+1, subtree+n+1, 0);
    fill(visited+1, visited+n+1, 0);

    queue<int> q;
    vector<pair<int, int>> X;
    visited[s] = 1;

    for (auto &v:adj[s]){
        visited[v] = 1;
        pa[v] = s;
        subtree[v] = v;
        q.push(v);
    }

    while(!q.empty()){
        int cur = q.front(); q.pop();
        for (auto &nxt:adj[cur]) if (nxt!=s){
            if (visited[nxt]){
                if (subtree[cur]==subtree[nxt]) continue;
                if (pa[cur]==s && pa[nxt]==s){
                    no[cur][nxt] = 1;
                    no[nxt][cur] = 1;
                    X.emplace_back(cur, nxt);
                }
                else if (no[subtree[cur]][subtree[nxt]]) continue;
                else{
                    getans(s, cur, nxt);
                }
            }
            else{
                visited[nxt] = 1;
                q.push(nxt);
                pa[nxt] = cur;
                subtree[nxt] = subtree[cur];
            }
        }
    }

    for (auto &[x, y]:X) no[x][y] = no[y][x] = 0;
}

int main(){
    int m;
    scanf("%d %d", &n, &m);
    for (int i=1;i<=m;i++){
        int x, y;
        scanf("%d %d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    for (int i=1;i<=n;i++){
        bfs(i);
    }
    printf("no\n");
    return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 724 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1576 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 18 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1620 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3936 KB Output is correct
2 Correct 8 ms 3028 KB Output is correct
3 Correct 463 ms 5284 KB Output is correct
4 Correct 188 ms 4812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 276 ms 5008 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 6736 KB Time limit exceeded
2 Halted 0 ms 0 KB -