Submission #154980

# Submission time Handle Problem Language Result Execution time Memory
154980 2019-09-25T19:18:28 Z TadijaSebez Pipes (CEOI15_pipes) C++11
40 / 100
1740 ms 50436 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=100050;
const int H=2*N;
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;
vector<int> E[N];
void AddEdge(int x, int y){ E[x].pb(y);E[y].pb(x);}
int disc[N],low[N],tid;
void DFS(int u, int p)
{
	disc[u]=low[u]=++tid;
	bool was=0;
	for(int v:E[u])
	{
		if(v==p && !was)
		{
			was=1;
		}
		else
		{
			if(!disc[v])
			{
				DFS(v,u);
				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:43: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:46: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 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3192 KB Output is correct
2 Correct 9 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 3064 KB Output is correct
2 Correct 137 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 3832 KB Output is correct
2 Correct 283 ms 3440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 401 ms 5240 KB Output is correct
2 Runtime error 346 ms 18780 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 577 ms 9956 KB Output is correct
2 Runtime error 549 ms 25272 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 916 ms 11088 KB Output is correct
2 Runtime error 846 ms 41948 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 1220 ms 13032 KB Output is correct
2 Runtime error 1174 ms 50436 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 1484 ms 16628 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 1740 ms 29168 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -