Submission #152743

# Submission time Handle Problem Language Result Execution time Memory
152743 2019-09-09T10:16:38 Z toloraia Pipes (CEOI15_pipes) C++17
40 / 100
5000 ms 65536 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 = 1e5 + 5, M = 6e6 + 5;

int n, m;

int K;

vector < int > g[N];
vector < int > GG[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;
    for (i = 0; i < nn[k]; i++){
        X = g[k][i];
        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]){
                cout << k << " " << to << endl;
            }
            up[k] = min (up[k], up[to]);
        }
    }
    int num = (int)GG[k].size();
    for (i = 0; i < num; i++){
        X = GG[k][i];
        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);
            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]++;
        if (BB[k] == 2){
            BB[k] = 0;
            GG[k].pb (AA[k]);
            AA[k] = 0;
        }
        AA[p] = AA[p] * K + k;
        BB[p]++;
        if (BB[p] == 2){
            BB[p] = 0;
            GG[p].pb (AA[p]);
            AA[p] = 0;
        }
        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]);
        B[k] = 0;
        A[k] = 0;
    }
    if (B[p] == 2){
        dam (p, A[p]);
        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]);
    for (i = 1; i <= n; i++)
        if (AA[i])
            GG[i].pb (AA[i]);
    for (i = 1; i <= n; i++)
        if (in[i] == 0)
            dfs (i, 0);
    return 0;
}

Compilation message

pipes.cpp:151:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5828 KB Output is correct
2 Correct 19 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 597 ms 10892 KB Output is correct
2 Correct 583 ms 10468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1078 ms 14636 KB Output is correct
2 Correct 1254 ms 16272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1847 ms 20896 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2464 ms 43336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4199 ms 65536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5051 ms 42164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5034 ms 35124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5065 ms 35432 KB Time limit exceeded
2 Halted 0 ms 0 KB -