답안 #680458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680458 2023-01-10T22:13:20 Z danikoynov Pipes (CEOI15_pipes) C++14
50 / 100
1155 ms 62172 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e5 + 10;
struct edge
{
    int v, u;
    edge(int _v, int _u)
    {
        v = _v;
        u = _u;
    }
};

int n, m;
int par1[maxn], par2[maxn];
int find_leader1(int v)
{
    if (v == par1[v])
        return v;
    return (par1[v] = find_leader1(par1[v]));
}

bool connected1(int v, int u)
{
    v = find_leader1(v);
    u = find_leader1(u);

    if (v == u)
        return true;
    par1[u] = v;
    return false;
}


int find_leader2(int v)
{
    if (v == par2[v])
        return v;
    return (par2[v] = find_leader2(par2[v]));
}
bool connected2(int v, int u)
{
    v = find_leader2(v);
    u = find_leader2(u);
    if (v == u)
        return true;

    par2[u] = v;
    return false;
}

vector < int > g[maxn];
int tin[maxn], low[maxn], timer;
void dfs(int v, int p)
{
    tin[v] = low[v] = ++ timer;
    ///cout << v << " : " << p << " " << g[v].size() << endl;
    bool tf = false;
    for (int u : g[v])
    {
        if (u == p && !tf)
        {
            tf = true;
            continue;
        }

        if (tin[u] != 0)
        {
            low[v] = min(low[v], tin[u]);
        }
        else
        {
            dfs(u, v);
            if (low[u] > tin[v])
                cout << v << " " << u << endl;
            low[v] = min(low[v], low[u]);
        }
    }
}
void solve()
{
    cin >> n >> m;
    int v, u;
    for (int i = 1; i <= n; i ++)
        par1[i] = i, par2[i] = i;
    for (int i = 1; i <= m; i ++)
    {
        cin >> v >> u;
        if (connected1(v, u))
        {
            if (!connected2(v, u))
             {
                 g[v].push_back(u);
                 g[u].push_back(v);
             }
        }
        else
        {
                             g[v].push_back(u);
                 g[u].push_back(v);
        }
    }


    for (int i = 1; i <= n; i ++)
        if (tin[i] == 0)
            dfs(i, 0);
}

int main()
{
    speed();
    solve();
    return 0;
}

/**
3 2
1 2
2 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3156 KB Output is correct
2 Correct 6 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 3104 KB Output is correct
2 Correct 81 ms 2940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 3904 KB Output is correct
2 Correct 178 ms 14620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 5732 KB Output is correct
2 Runtime error 232 ms 19240 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 11980 KB Output is correct
2 Runtime error 317 ms 25468 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 603 ms 13328 KB Output is correct
2 Correct 538 ms 15452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 677 ms 15800 KB Output is correct
2 Runtime error 710 ms 18300 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 852 ms 15888 KB Output is correct
2 Runtime error 863 ms 62172 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1014 ms 15128 KB Output is correct
2 Runtime error 1155 ms 57264 KB Memory limit exceeded
3 Halted 0 ms 0 KB -