Submission #959105

# Submission time Handle Problem Language Result Execution time Memory
959105 2024-04-07T13:40:00 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
40 / 100
831 ms 59068 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 n, m, tin[N], tmp, par[2][N], sz[2][N];

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

bool join(int u, int v, int t)
{
	u = get(u, t), v = get(v, t);
	if(u == v)	return false;
	if(sz[t][u] > sz[t][v])	swap(u, v);
	par[t][u] = v;
	sz[t][v] += sz[t][u];
	return true;
}
 
int dfs(int src, int pa = -1)
{
	int low, idx = 0;
	tin[src] = low = ++tmp;
	for(auto it : adj[src])
	{
		if(it == pa)
		{
			idx++;	
			continue;
		}
		if(tin[it])
		{
			low = min(low, tin[it]);
			idx++;	
			continue;
		}
		int low_it = dfs(it, src);
		low = min(low, low_it);
		if(idx && adj[src][idx-1] == it)	
		{
			idx++;
			continue;
		}
		if(idx+1 < adj[src].size() && adj[src][idx+1] == it)	
		{
			idx++;
			continue;
		}
		if(low_it > tin[src])
		{
			cout << src << ' ' << it << endl;
		}
		idx++;		
	}
	return low;
}
 
int main()
{
	fastio;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)	par[0][i] = par[1][i] = i, sz[0][i] = sz[1][i] = 1;
	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++)	sort(adj[i].begin(), adj[i].end());
	for(int i = 1; i <= n; i++)
	{
		if(!tin[i])	dfs(i);
	}
 
    return 0;
}

Compilation message

pipes.cpp: In function 'int dfs(int, int)':
pipes.cpp:52:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   if(idx+1 < adj[src].size() && adj[src][idx+1] == it)
      |      ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4956 KB Output is correct
2 Correct 6 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 4948 KB Output is correct
2 Correct 68 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 5504 KB Output is correct
2 Correct 136 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 15692 KB Output is correct
2 Runtime error 170 ms 20792 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 299 ms 22668 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 403 ms 30508 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 579 ms 37900 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 693 ms 46220 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 831 ms 59068 KB Memory limit exceeded
2 Halted 0 ms 0 KB -