답안 #317009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317009 2020-10-29T00:54:29 Z caoash Potemkin cycle (CEOI15_indcyc) C++14
10 / 100
1000 ms 71984 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

namespace output {
  void pr(int x) {
    cout << x;
  }
  void pr(long x) {
    cout << x;
  }
  void pr(ll x) {
    cout << x;
  }
  void pr(unsigned x) {
    cout << x;
  }
  void pr(unsigned long x) {
    cout << x;
  }
  void pr(unsigned long long x) {
    cout << x;
  }
  void pr(float x) {
    cout << x;
  }
  void pr(double x) {
    cout << x;
  }
  void pr(long double x) {
    cout << x;
  }
  void pr(char x) {
    cout << x;
  }
  void pr(const char * x) {
    cout << x;
  }
  void pr(const string & x) {
    cout << x;
  }
  void pr(bool x) {
    pr(x ? "true" : "false");
  }

  template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
  template < class T > void pr(const T & x);

  template < class T, class...Ts > void pr(const T & t,
    const Ts & ...ts) {
    pr(t);
    pr(ts...);
  }
  template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
    pr("{", x.f, ", ", x.s, "}");
  }
  template < class T > void pr(const T & x) {
    pr("{"); // const iterator needed for vector<bool>
    bool fst = 1;
    for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
    pr("}");
  }

  void ps() {
    pr("\n");
  } // print w/ spaces
  template < class T, class...Ts > void ps(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(" ");
    ps(ts...);
  }

  void pc() {
    cout << "]" << endl;
  } // debug w/ commas
  template < class T, class...Ts > void pc(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(", ");
    pc(ts...);
  }
  #define dbg(x...) pr("[", #x, "] = ["), pc(x);
}

#ifndef ONLINE_JUDGE
using namespace output;
#else
using namespace output;
#define dbg(x...)
#endif

const int MX = 1001;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

int n, m;
set<int> adj[MX];
map<pi, vector<pi>> fin;
set<pi> vis;
vector<pi> ed;
map<pi, pi> anc;
bool found = false;

void dfs(pi v, pi p) {
    if (found) return;
    vis.insert(v);
    // dbg(v, p);
    for (pi to : fin[v]) {
        if (to != p) {
            if (vis.count(to)) {
                found = true;
                while(v != to) {
                    cout << v.s + 1 << " "; 
                    v = anc[v];
                }
                cout << to.s + 1 << '\n';
                return;
            } else {
                anc[to] = v;
                dfs(to, v);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m; 
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        u--, v--;
        adj[u].insert(v), adj[v].insert(u);
        ed.pb(mp(u, v));
        ed.pb(mp(v, u));
    }
    for (int i = 0; i < sz(ed); i++) {
        int u = ed[i].f, v = ed[i].s;
        for (int j = 0; j < n; j++) {
            // dbg(u, v, j, adj[v].count(j), adj[u].count(j));
            if (j != u && j != v && adj[v].count(j) && !adj[u].count(j)) {
                fin[mp(u, v)].pb(mp(v, j));
            }
        }
    }
    for (int i = 0; i < sz(ed); i++) {
        if (!vis.count(ed[i])) dfs(ed[i], mp(-1, -1));
    }
    if (!found) cout << "no" << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 1061 ms 29432 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Execution timed out 1084 ms 26708 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 25592 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 25080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 25456 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 25328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 22756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 71984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 11108 KB Time limit exceeded
2 Halted 0 ms 0 KB -