Submission #959121

# Submission time Handle Problem Language Result Execution time Memory
959121 2024-04-07T13:55:22 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
50 / 100
823 ms 49636 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];
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;
}
 
int dfs(int src, int pa = -1)
{
	int low;
	bool v = 0;
	tin[src] = low = ++tmp;
	for(auto it : adj[src])
	{
		if(it == pa && !v)
		{
			v = 1;
			continue;
		}
		if(tin[it])
		{
			low = min(low, tin[it]);
			continue;
		}
		int low_it = dfs(it, src);
		low = min(low, low_it);
		if(low_it > tin[src])
		{
			cout << src << ' ' << it << '\n';
		}
	}
	return low;
}
 
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 2 ms 3676 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4188 KB Output is correct
2 Correct 4 ms 4112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7380 KB Output is correct
2 Correct 69 ms 7132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 10304 KB Output is correct
2 Correct 147 ms 10632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 15376 KB Output is correct
2 Correct 181 ms 13264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 283 ms 22476 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 418 ms 30124 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 556 ms 37284 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 699 ms 42868 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 823 ms 49636 KB Memory limit exceeded
2 Halted 0 ms 0 KB -