답안 #152749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152749 2019-09-09T10:24:17 Z toloraia Pipes (CEOI15_pipes) C++17
40 / 100
1852 ms 17512 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll long long
//#define ll __int128
#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))
/*
#pragma comment(linker, "/STACK: 20000000005")
#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 ("O3")
#pragma GCC optimization ("unroll-loops")
*/
using namespace std;

const int N = 3e4 + 5, M = 6e6 + 5;

int n, m;

int K;

vector < int > g[N];
int A[N], AA[N];
int B[N], BB[N];
int x, y;
int T;
int in[N], up[N];

int nn[N], mi[N], sz[N];



void dfs (int k, int p){
    in[k] = ++T;
    up[k] = in[k];
    int to, i, toto;
    int X;
    bool ok;
    for (i = 0; i < nn[k]; i++){
        X = g[k][i];
        ok = 0;
        if (X % 2 == 0)
            ok = 1;
        X /= 2;
        while (X){
            toto = X % K;
            X /= K;
            to = toto;
            if (to > n)
                to -= n;
            if (to == p)
                continue;
            if (in[to]){
                up[k] = min (up[k], in[to]);
                continue;
            }
            dfs (to, k);
            if (up[to] > in[k] && ok == 1){
                cout << k << " " << to << endl;
            }
            up[k] = min (up[k], up[to]);
        }
    }
}

void dam (int k, int x){
    if (nn[k] >= sz[k]){
        g[k].pb (x);
        nn[k]++;
        return;
    }
    g[k][nn[k]++] = x;
}

int p;
bool ok;

void midi (int k){
    if (mi[k] >= sz[k])
        return;
    p = g[k][mi[k]];
    ok = 0;
    if (mi[k] < sz[k] - 1 && g[k][mi[k] + 1] == p)
        ok = 1;
    while (mi[k] < sz[k] - 1 && g[k][mi[k] + 1] == p)
        mi[k]++;
    mi[k]++;
    if (ok){
        AA[k] = AA[k] * K + p;
        BB[k]++;
        AA[p] = AA[p] * K + k;
        BB[p]++;
        if (BB[k] == 2){
            dam (k, AA[k] * 2 + 1);
            BB[k] = 0;
            AA[k] = 0;
        }
        if (BB[p] == 2){
            dam (p, AA[p] * 2 + 1);
            BB[p] = 0;
            AA[p] = 0;
        }
        midi (p);
        return;
    }
    A[k] = A[k] * K + p;
    B[k]++;
    A[p] = A[p] * K + k;
    B[p]++;
    if (B[k] == 2){
        dam (k, A[k] * 2);
        B[k] = 0;
        A[k] = 0;
    }
    if (B[p] == 2){
        dam (p, A[p] * 2);
        B[p] = 0;
        A[p] = 0;
    }
    midi (p);
}


int t, num;
int j;
int i, to;


main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    //ios_base::sync_with_stdio(false);
    cin >> n >> m;
    K = n + 1;
    for (i = 1; i <= m; i++){
        cin >> x >> y;
        if (x > y)
            swap (x, y);
        g[x].pb (y);
        sz[x]++;
    }
    for (i = 1; i <= n; i++){
        sort (g[i].begin(), g[i].end());
    }
    for (int i = 1; i <= n; i++){
        while (mi[i] < sz[i])
            midi (i);
    }
    for (i = 1; i <= n; i++)
        if (A[i])
            dam (i, A[i] * 2);
    for (i = 1; i <= n; i++)
        if (AA[i])
            dam (i, AA[i] * 2 + 1);
    for (i = 1; i <= n; i++)
        if (in[i] == 0)
            dfs (i, 0);
    return 0;
}

Compilation message

pipes.cpp:137:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1784 KB Output is correct
2 Correct 15 ms 1472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 580 ms 7684 KB Output is correct
2 Correct 558 ms 6672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1058 ms 11316 KB Output is correct
2 Correct 1226 ms 10816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1852 ms 17512 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1912 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1912 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1856 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1916 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1784 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -