Submission #959118

# Submission time Handle Problem Language Result Execution time Memory
959118 2024-04-07T13:50:14 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
50 / 100
854 ms 49164 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<vector<int>> adj;
vector<int> tin;
vector<array<int, 2>> par;
int n, m, tmp;

int get(int src, int t)
{
	if(src == par[src][t])	return src;
	return par[src][t] = get(par[src][t], t);
}

bool join(int u, int v, int t)
{
	u = get(u, t), v = get(v, t);
	if(u == v)	return false;
	par[u][t] = v;
	return true;
}
 
int dfs(int src, int pa = -1)
{
	int low, idx = 0, v = 0;
	tin[src] = low = ++tmp;
	for(auto it : adj[src])
	{
		if(it == pa && !v)
		{
			v = 1;
			idx++;	
			continue;
		}
		if(tin[it])
		{
			low = min(low, tin[it]);
			idx++;	
			continue;
		}
		int low_it = dfs(it, src);
		low = min(low, low_it);
		idx++;		
		if(low_it > tin[src])
		{
			cout << src << ' ' << it << endl;
		}
	}
	return low;
}
 
int main()
{
	fastio;
	cin >> n >> m;
	adj = vector<vector<int>> (n+1);
	par = vector<array<int, 2>> (n+1);
	tin = vector<int> (n+1);
	for(int i = 1; i <= n; i++)	par[i] = {i, i};
	for(int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		if(join(u, v, 0) || join(u, v, 1))	
		{
			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 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1116 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 4256 KB Output is correct
2 Correct 69 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 7252 KB Output is correct
2 Correct 137 ms 7492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 12768 KB Output is correct
2 Correct 177 ms 10764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 280 ms 21424 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 473 ms 29312 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 563 ms 37328 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 713 ms 43004 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 854 ms 49164 KB Memory limit exceeded
2 Halted 0 ms 0 KB -