답안 #485289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485289 2021-11-07T03:14:20 Z SirCovidThe19th Potemkin cycle (CEOI15_indcyc) C++17
0 / 100
252 ms 53728 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1005, mxM = 2e5 + 5;

int n, m, u[mxM], v[mxM], adj1[mxN][mxN]; vector<int> adj2[mxM], stk; bool vis[mxM], active[mxM];

void dfs(int cur, int p){
    vis[cur] = active[cur] = 1; stk.push_back(cur);
    for (int nxt : adj2[cur]) if (nxt != p and active[nxt]){
        while (stk.back() != nxt){
            int x = stk.back();
            cout<<u[stk.back()]<<" ";
            stk.pop_back();
        } 
        cout<<u[stk.back()]<<endl;
        exit(1);
    }
    for (int nxt : adj2[cur]) if (nxt != p and !vis[nxt]) dfs(nxt, cur);
    active[cur] = 0; stk.pop_back();
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); 
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int a, b; cin >> a >> b; 
        u[i * 2] = a; v[i * 2] = b;
        u[i * 2 + 1] = b; v[i * 2 + 1] = a;
        adj1[a][b] = i * 2; adj1[b][a] = i * 2 + 1;
    }
    for (int i = 1; i <= 2 * m; i++)
        for (int j = 1; j <= n; j++)
            if (adj1[v[i]][j] and j != u[i])
                if (!adj1[u[i]][j])
                    adj2[i].push_back(adj1[v[i]][j]);

    for (int i = 1; i <= 2 * m; i++) if (!vis[i]) dfs(i, 0);
    cout<<"no"<<endl;
}

Compilation message

indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:12:17: warning: unused variable 'x' [-Wunused-variable]
   12 |             int x = stk.back();
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 4940 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5068 KB Execution failed because the return code was nonzero
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5024 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5452 KB Execution failed because the return code was nonzero
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 5580 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6476 KB Output is correct
2 Runtime error 8 ms 6460 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 7756 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 252 ms 25040 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 155 ms 53728 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 162 ms 9472 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -