Submission #154848

# Submission time Handle Problem Language Result Execution time Memory
154848 2019-09-25T10:40:19 Z TadijaSebez Pipes (CEOI15_pipes) C++11
50 / 100
1711 ms 54524 KB
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
const int M=4*N;
struct DSU
{
	int p[N];
	DSU(){}
	int Find(int x){ return !p[x]?x:p[x]=Find(p[x]);}
	void Union(int x, int y){ p[Find(x)]=Find(y);}
	bool Same(int x, int y){ return Find(x)==Find(y);}
} D1,D2;
int go[M],fir[N],tsz=1,f[M];
void Add(int x, int y){ tsz++;go[tsz]=fir[x];f[tsz]=y;fir[x]=tsz;}
void AddEdge(int x, int y){ Add(x,y);Add(y,x);}
int disc[N],low[N],tid;
void DFS(int u, int p)
{
	disc[u]=low[u]=++tid;
	for(int i=fir[u];i;i=go[i]) if(i/2!=p)
	{
		int v=f[i];
		if(!disc[v])
		{
			DFS(v,i/2);
			if(low[v]>disc[u]) printf("%i %i\n",u,v);
			low[u]=min(low[u],low[v]);
		}
		else low[u]=min(low[u],disc[v]);
	}
}
int main()
{
	int n,m,u,v;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%i %i",&u,&v);
		if(!D1.Same(u,v))
		{
			D1.Union(u,v);
			AddEdge(u,v);
		}
		else if(!D2.Same(u,v))
		{
			D2.Union(u,v);
			AddEdge(u,v);
		}
	}
	for(int i=1;i<=n;i++) if(!disc[i]) DFS(i,-1);
	return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
pipes.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&u,&v);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 6156 KB Output is correct
2 Correct 136 ms 5884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 9116 KB Output is correct
2 Correct 280 ms 6008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 6904 KB Output is correct
2 Correct 341 ms 16136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 532 ms 7792 KB Output is correct
2 Runtime error 505 ms 22520 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Runtime error 852 ms 17572 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1110 ms 31172 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1471 ms 42440 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1711 ms 54524 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -