Submission #959293

# Submission time Handle Problem Language Result Execution time Memory
959293 2024-04-07T22:33:00 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
40 / 100
793 ms 58144 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5+5;
 
vector<int> adj[N];
int tin[N], par[N][2], low[N];
 
 
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 n, m, tmp, u, v;
void dfs(int src, int pa = -1)
{
	bool a = 0;
	tin[src] = low[src] = ++tmp;
	for(auto it : adj[src])
	{
		if(it == pa && !a)
		{
			a = 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()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++)	par[i][0] = par[i][1] = i;
	int a = 0;
	for(int i = 0; i < m; i++)
	{
		cin >> u >> v;
		if(join1(u, v) || join2(u, v))	
		{
			adj[u].push_back(v), adj[v].push_back(u);
			a += 2;
		}
	}
	assert(a <= n*10);
	for(int i = 1; i <= n; i++)
	{
		if(!tin[i])	dfs(i);
	}
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4632 KB Output is correct
2 Correct 4 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7608 KB Output is correct
2 Correct 67 ms 7180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 10120 KB Output is correct
2 Correct 136 ms 10504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 15188 KB Output is correct
2 Runtime error 159 ms 20048 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 275 ms 22376 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 403 ms 29872 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 533 ms 37120 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 641 ms 45304 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 793 ms 58144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -