Submission #728071

#TimeUsernameProblemLanguageResultExecution timeMemory
728071n0sk1llPipes (CEOI15_pipes)C++17
90 / 100
993 ms22856 KiB
#include <vector>
#include <iostream>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define pb push_back
#define popb pop_back
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;

int up[2][100005];

int Up(bool c, int x)
{
    if (up[c][x]<0) return x;
    return up[c][x]=Up(c,up[c][x]);
}

bool dsu(bool c, int a, int b)
{
    a=Up(c,a),b=Up(c,b);
    if (a==b) return false;
    if (up[c][a]<up[c][b]) swap(a,b);
    up[c][b]+=up[c][a],up[c][a]=b;
    return true;
}

int par[100010];
int idx[100010];
int lowl[100010];
int nt;
vector<int> edge[100010];

void dfs(int x){
	idx[x] = lowl[x] = ++nt;
	bool cl = false;
	for(int y:edge[x]){
		if(par[x] == y && !cl){
			cl=true; continue;
		}
		if(!idx[y]){
			par[y]=x;
			dfs(y);
			lowl[x] = min(lowl[x], lowl[y]);
		} else lowl[x] = min(lowl[x], idx[y]);
	}
	if(par[x] && idx[x]==lowl[x]) cout<<x<<" "<<par[x]<<"\n";
}

int main()
{
    FAST;

    int n,m; cin>>n>>m;
    ff(c,0,2) fff(i,1,n) up[c][i]=-1;

    while (m--)
    {
        int u,v; cin>>u>>v;
        if (dsu(0,u,v) || dsu(1,u,v)) edge[u].pb(v),edge[v].pb(u);
    }

    fff(i,1,n) if (up[0][i]<0) dfs(i);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...