Submission #598981

# Submission time Handle Problem Language Result Execution time Memory
598981 2022-07-19T08:37:52 Z 이동현(#8460) Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
30 ms 7520 KB
#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> way[1004];
int chk[1004], ss, from[1004], did[1004], didN;

void bfs(int s, int e){
    queue<int> que;
    que.push(s);
    did[s] = didN;
    while(!que.empty()){
        int now = que.front(); que.pop();
        for(auto&nxt:way[now]){
            if((nxt != e && !chk[nxt]) || did[nxt] == didN) continue;
            from[nxt] = now;
            que.push(nxt);
            did[nxt] = didN;
        }
    }
    if(did[e] == didN){
        int now = e;
        while(true){
            cout << now << ' ';
            if(now == s) break;
            now = from[now];
        }
        cout << ss << '\n';
        exit(0);
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    map<pair<int, int>, int> cant;
    for(int i = 1; i <= m; ++i){
        int x, y; cin >> x >> y;
        way[x].push_back(y);
        way[y].push_back(x);
        cant[{x, y}] = 1;
    }
    for(int i = 1; i <= n; ++i) chk[i] = 1;
    for(int i = 1; i <= n; ++i){
        chk[i] = 0;
        sort(way[i].begin(), way[i].end());
        for(auto&nxt:way[i]){
            chk[nxt] = 0;
        }
        ss = i;
        for(int j = 0; j < (int)way[i].size(); ++j){
            for(int k = j + 1; k < (int)way[i].size(); ++k){
                if(cant[{way[i][j], way[i][k]}]) continue;
                ++didN;
                bfs(way[i][j], way[i][k]);
            }
        }
        chk[i] = 1;
        for(auto&nxt:way[i]){
            chk[nxt] = 1;
        }
    }
    cout << "no\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Too short sequence
2 Incorrect 1 ms 340 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Too short sequence
2 Incorrect 1 ms 340 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Too short sequence
2 Incorrect 2 ms 616 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3976 KB Too short sequence
2 Correct 7 ms 1996 KB Too short sequence
3 Incorrect 18 ms 4044 KB Wrong answer on graph without induced cycle
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1876 KB Too short sequence
2 Incorrect 8 ms 2004 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 7520 KB Too short sequence
2 Incorrect 29 ms 7364 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -