Submission #959312

# Submission time Handle Problem Language Result Execution time Memory
959312 2024-04-07T23:29:43 Z Cyber_Wolf Pipes (CEOI15_pipes) C++17
40 / 100
1014 ms 52224 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]));
}
 
int get2(int src)
{
	return par[src][1] = (src == par[src][1] ? src : get2(par[src][1]));
}
 
int n, m, tmp, pa = -1;
void dfs(int src)
{
	bool a = false;
	tin[src] = low[src] = ++tmp;
	for(auto it : adj[src])
	{
		if(it == pa && !a)
		{
			a = true;
			continue;
		}
		if(tin[it])
		{
			low[src] = min(low[src], tin[it]);
			continue;
		}
		swap(pa, src);
		dfs(it);
		swap(pa, src);
		low[src] = min(low[src], low[it]);
		if(low[it] > tin[src])
		{
			printf("%d %d\n", src, it);
		}
	}
	return ;
}
 
int main()
{	
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)	par[i][0] = par[i][1] = i;
	int u, v, pU, pV;
	while(m--)
	{
		scanf("%d%d", &u, &v);
		pU = get1(u), pV = get1(v);
		if(pU != pV)
		{
			par[pU][0] = pV;
			adj[u].push_back(v), adj[v].push_back(u);
		}
		else{
			pU = get2(u), pV = get2(v);
			if(pU != pV)
			{
				par[pU][1] = pV;
				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:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   scanf("%d%d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3932 KB Output is correct
2 Correct 1 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4444 KB Output is correct
2 Correct 4 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 7372 KB Output is correct
2 Correct 100 ms 7100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 10160 KB Output is correct
2 Correct 173 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 14792 KB Output is correct
2 Runtime error 206 ms 19804 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 310 ms 21088 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 504 ms 28308 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 630 ms 35276 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 834 ms 41604 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1014 ms 52224 KB Memory limit exceeded
2 Halted 0 ms 0 KB -