답안 #134999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134999 2019-07-23T13:56:34 Z lyc Potemkin cycle (CEOI15_indcyc) C++14
100 / 100
392 ms 91960 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MAXN = 1e3+5;
const int MAXR = 1e5+5;
const int MAXE = 2*MAXR;

int N, R;
vector<int> al[MAXN];
bool conn[MAXN][MAXN];

vector<int> g[MAXE];
int E, from[MAXE], to[MAXE], vis[MAXE], pa[MAXE];

void bfs(int s) {
    queue<int> q;
    FOR(i,0,E-1) pa[i] = -1;
    q.push(s);
    //cout << "S " << from[s] << " " << to[s] << endl;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        //cout << "U " << from[u] << " " << to[u] << endl;
        for (int v : g[u]) {
            //cout << "\t\tV " << from[v] << " " << to[v] << endl;
            if (v == s) {
                //cout << "ANS" << '\n';
                //vector<int> edges;
                //for (int e = u; e != -1; e = pa[e]) edges.push_back(e);
                //for (auto& e : edges) { cout << from[e] << " " << to[e] << " :: "; } cout << endl;
                for (int e = u; e != -1; e = pa[e]) cout << to[e] << (pa[e]==-1?'\n':' ');
                exit(0);
            } else if (pa[v] == -1) pa[v] = u, q.push(v);
        }
    }
}

void dfs(int u) {
    vis[u] = 2;
    for (int v : g[u]) {
        if (vis[v] == 2) {
            bfs(v); // ans
        } else if (!vis[v]) dfs(v);
    }
    vis[u] = 1;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> R; E = 0;
    FOR(i,1,R){
        int A, B; cin >> A >> B;
        from[E] = A, to[E] = B;
        al[A].push_back(E++);
        from[E] = B, to[E] = A;
        al[B].push_back(E++);
        conn[A][B] = conn[B][A] = 1;
    }

    FOR(i,1,N) FOR(j,0,SZ(al[i])-1) { // + ^ O(E)
        FOR(k,j+1,SZ(al[i])-1) { // O(N)
            int e = al[i][j], f = al[i][k];
            if (!conn[to[e]][to[f]]) g[e^1].push_back(f), g[f^1].push_back(e);
        }
    }

    FOR(i,0,E-1) vis[i] = 0;
    FOR(i,0,E-1) if (!vis[i]) dfs(i);
    cout << "no" << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5116 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5496 KB Output is correct
2 Correct 8 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5752 KB Output is correct
2 Correct 9 ms 5752 KB Output is correct
3 Correct 18 ms 7764 KB Output is correct
4 Correct 21 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7032 KB Output is correct
2 Correct 17 ms 7032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 23068 KB Output is correct
2 Correct 39 ms 9976 KB Output is correct
3 Correct 138 ms 23004 KB Output is correct
4 Correct 50 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 51372 KB Output is correct
2 Correct 173 ms 55448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 9932 KB Output is correct
2 Correct 136 ms 9384 KB Output is correct
3 Correct 377 ms 91960 KB Output is correct
4 Correct 392 ms 91416 KB Output is correct