Submission #959300

# Submission time Handle Problem Language Result Execution time Memory
959300 2024-04-07T23:07:47 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
50 / 100
839 ms 64508 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)
{
	return par[src][0] = (src == par[src][0] ? src : 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)
{
	return par[src][1] = (src == par[src][1] ? src : 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;
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])
		{
			printf("%d %d\n", src, it);
		}
	}
	return ;
}
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)	par[i][0] = par[i][1] = i;
	int u, v;
	while(m--)
	{
		scanf("%d%d", &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;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%d%d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4444 KB Output is correct
2 Correct 4 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 4432 KB Output is correct
2 Correct 72 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 5080 KB Output is correct
2 Correct 149 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 6416 KB Output is correct
2 Correct 174 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 11344 KB Output is correct
2 Runtime error 245 ms 21332 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 460 ms 12032 KB Output is correct
2 Runtime error 418 ms 34640 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 560 ms 13908 KB Output is correct
2 Runtime error 543 ms 40476 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 688 ms 14068 KB Output is correct
2 Runtime error 676 ms 49176 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 839 ms 13596 KB Output is correct
2 Runtime error 838 ms 64508 KB Memory limit exceeded
3 Halted 0 ms 0 KB -