Submission #959122

# Submission time Handle Problem Language Result Execution time Memory
959122 2024-04-07T13:57:54 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
50 / 100
801 ms 45136 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
const int N = 1e5+5;
 
vector<int> adj[N];
int tin[N], par[N][2], low[N];
int n, m, tmp;


int get1(int src)
{
	if(src == par[src][0])	return src;
	return par[src][0] = get1(par[src][0]);
}

bool join1(int u, int v)
{
	u = get1(u), v = get1(v);
	if(u == v)	return false;
	par[u][0] = v;
	return true;
}

int get2(int src)
{
	if(src == par[src][1])	return src;
	return par[src][1] = get2(par[src][1]);
}

bool join2(int u, int v)
{
	u = get2(u), v = get2(v);
	if(u == v)	return false;
	par[u][1] = v;
	return true;
}
 
void dfs(int src, int pa = -1)
{
	bool v = 0;
	tin[src] = low[src] = ++tmp;
	for(auto it : adj[src])
	{
		if(it == pa && !v)
		{
			v = 1;
			continue;
		}
		if(tin[it])
		{
			low[src] = min(low[src], tin[it]);
			continue;
		}
		dfs(it, src);
		low[src] = min(low[src], low[it]);
		if(low[it] > tin[src])
		{
			cout << src << ' ' << it << '\n';
		}
	}
	return ;
}
 
int main()
{
	fastio;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)	par[i][0] = par[i][1] = i;
	for(int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		if(join1(u, v) || join2(u, v))	
		{
			adj[u].push_back(v), adj[v].push_back(u);
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(!tin[i])	dfs(i);
	}
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4444 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 4340 KB Output is correct
2 Correct 63 ms 4336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 5076 KB Output is correct
2 Correct 127 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 6672 KB Output is correct
2 Correct 166 ms 6092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 11760 KB Output is correct
2 Runtime error 247 ms 17352 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 404 ms 12936 KB Output is correct
2 Runtime error 372 ms 26848 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 538 ms 14836 KB Output is correct
2 Runtime error 518 ms 30400 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 666 ms 14832 KB Output is correct
2 Runtime error 635 ms 36200 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 801 ms 14440 KB Output is correct
2 Runtime error 757 ms 45136 KB Memory limit exceeded
3 Halted 0 ms 0 KB -