Submission #594249

# Submission time Handle Problem Language Result Execution time Memory
594249 2022-07-12T09:27:46 Z andrei_boaca Pipes (CEOI15_pipes) C++14
30 / 100
3841 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;
vector<int> muchii[100005];
vector<int> dsu1[100005],dsu2[100005];
int comp1[100005],comp2[100005],par[100005],niv[100005],nivmin[100005];
bool use[100005];
int n,m;
void dfs(int nod)
{
    use[nod]=1;
    nivmin[nod]=niv[nod];
    for(int i:muchii[nod])
    {
        int node=i;
        if(node==par[nod])
            continue;
        if(!use[node])
        {
            par[node]=nod;
            niv[node]=niv[nod]+1;
            dfs(node);
            nivmin[nod]=min(nivmin[nod],nivmin[node]);
        }
        else
            nivmin[nod]=min(nivmin[nod],niv[node]);
    }
    int cnt=0;
    if(nivmin[nod]==niv[nod]&&par[nod]!=0)
    {
        for(int i:muchii[nod])
            if(i==par[nod])
                cnt++;
        if(cnt==1)
            cout<<par[nod]<<' '<<nod<<'\n';
    }
}
void dsu_merge1(int c1,int c2)
{
    if(dsu1[c1].size()<dsu1[c2].size())
        swap(c1,c2);
    for(int i:dsu1[c2])
    {
        comp1[i]=c1;
        dsu1[c1].push_back(i);
    }
    dsu1[c2].clear();
}
void dsu_merge2(int c1,int c2)
{
    if(dsu2[c1].size()<dsu2[c2].size())
        swap(c1,c2);
    for(int i:dsu2[c2])
    {
        comp2[i]=c1;
        dsu2[c1].push_back(i);
    }
    dsu2[c2].clear();
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        dsu1[i].push_back(i);
        dsu2[i].push_back(i);
        comp1[i]=i;
        comp2[i]=i;
    }
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(comp1[a]!=comp1[b])
        {
            dsu_merge1(comp1[a],comp2[b]);
            muchii[a].push_back(b);
            muchii[b].push_back(a);
        }
        else
        {
            if(comp2[a]!=comp2[b])
            {
                dsu_merge2(comp2[a],comp2[b]);
                muchii[a].push_back(b);
                muchii[b].push_back(a);
            }
        }
    }
    for(int i=1;i<=n;i++)
        if(!use[i])
            dfs(i);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7352 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8356 KB Output is correct
2 Correct 13 ms 8132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 13768 KB Output is correct
2 Correct 307 ms 15560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 575 ms 29448 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 787 ms 30620 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1213 ms 50668 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1901 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2796 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3364 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3841 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -