Submission #96163

# Submission time Handle Problem Language Result Execution time Memory
96163 2019-02-06T14:58:40 Z popovicirobert Pipes (CEOI15_pipes) C++14
100 / 100
1192 ms 14040 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const int Nmax = 1e5 + 5;
 
int n, m, i, x, y;
int level[Nmax], low[Nmax];
vector<int> v[Nmax];
 
struct Forest
{
    int t[Nmax];
 
    void clear()
    {
        int i;
        for(i=1; i<=n; ++i) t[i] = i;
    }
 
    int boss(int x)
    {
        if(t[x] == x) return x;
        return t[x] = boss(t[x]);
    }
 
    void unite(int x, int y)
    {
        x = boss(x), y = boss(y);
        t[x] = y;
    }
} A, B;
 
void solve(int node, int dad = 0)
{
    level[node] = low[node] = level[dad] + 1;
 
    bool ok = 0;
    for(auto son : v[node])
    {
        if(son == dad && !ok)
        {
            ok = 1;
            continue;
        }
 
        if(level[son])
        {
            low[node] = min(low[node], level[son]);
            continue;
        }
 
        solve(son, node);
        low[node] = min(low[node], low[son]);
 
        if(low[son] == level[son])
            cout << node << ' ' << son << '\n';
    }
}
 
int main()
{
  //  freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
    cin.sync_with_stdio(false);
 
    cin >> n >> m;
    A.clear(); B.clear();
 
    while(m--)
    {
        cin >> x >> y;
        if(B.boss(x) == B.boss(y)) continue; /// same bcomp
 
        if(A.boss(x) != A.boss(y)) A.unite(x, y);
            else B.unite(x, y);
 
        v[x].push_back(y);
        v[y].push_back(x);
    }
 
    for(i=1; i<=n; ++i)
        if(!level[i]) solve(i);
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3200 KB Output is correct
2 Correct 7 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 3044 KB Output is correct
2 Correct 96 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 3804 KB Output is correct
2 Correct 191 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 5420 KB Output is correct
2 Correct 243 ms 5000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 412 ms 10616 KB Output is correct
2 Correct 360 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 621 ms 11864 KB Output is correct
2 Correct 630 ms 9108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 846 ms 14040 KB Output is correct
2 Correct 826 ms 9204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1046 ms 13920 KB Output is correct
2 Correct 950 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1192 ms 13412 KB Output is correct
2 Correct 1111 ms 10620 KB Output is correct