답안 #152680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152680 2019-09-09T07:08:06 Z toloraia Potemkin cycle (CEOI15_indcyc) C++17
80 / 100
1000 ms 5276 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122


#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
/*
#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const int N = 1005, M = 100005;

int n, m;

int u[M], v[M];

int G[N][N];

vector < int > g[N];
int d[N];
int par[N], fix[N];

queue < int > Q;

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        cin >> u[i] >> v[i];
        G[u[i]][v[i]] = 1;
        G[v[i]][u[i]] = 1;
        g[u[i]].pb (v[i]);
        g[v[i]].pb (u[i]);
    }
    for (int I = 1; I <= n; I++){
        for (int i = 1; i <= n; i++){
            par[i] = 0;
            fix[i] = 0;
            d[i] = 0;
        }
        fix[I] = I;
        for (int i = 1; i <= m; i++){
            if (G[I][u[i]] + G[I][v[i]] == 2){
                G[u[i]][v[i]] = 0;
                G[v[i]][u[i]] = 0;
            }
        }
        for (int i = 1; i <= n; i++){
            if (fix[i] > 0 || G[I][i] == 0)
                continue;
            fix[i] = i;
            Q.push (i);
            while (Q.size() > 0){
                int k = Q.front();
                Q.pop();
                if (fix[k] != k && G[I][k] == 1)
                    continue;
                for (int to : g[k]){
                    if (fix[to] > 0 || G[k][to] == 0)
                        continue;
                    if (G[I][to] == 1 && G[fix[k]][to] == 1)
                        continue;
                    fix[to] = fix[k];
                    par[to] = k;
                    d[to] = d[k] + 1;
                    Q.push (to);
                }
            }
        }
        for (int i = 1; i <= m; i++){
            G[u[i]][v[i]] = 1;
            G[v[i]][u[i]] = 1;
        }
        for (int k : g[I]){
            int p = fix[k];
            if (p == k)
                continue;
            if (G[I][p] == 0 || G[k][p] == 1)
                continue;
            int x = k;
            cout << I << " ";
            while (x){
                cout << x << " ";
                x = par[x];
            }
            return 0;
        }
    }
    cout << "no" << endl;
    return 0;
}

Compilation message

indcyc.cpp:21:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
indcyc.cpp:42:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1656 KB Output is correct
2 Correct 4 ms 1656 KB Output is correct
3 Correct 6 ms 1656 KB Output is correct
4 Correct 34 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1656 KB Output is correct
2 Correct 21 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5240 KB Output is correct
2 Correct 23 ms 4856 KB Output is correct
3 Correct 757 ms 5276 KB Output is correct
4 Correct 304 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 413 ms 4804 KB Output is correct
2 Correct 477 ms 4828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 3832 KB Time limit exceeded
2 Halted 0 ms 0 KB -