Submission #169417

# Submission time Handle Problem Language Result Execution time Memory
169417 2019-12-20T09:53:27 Z gs18103 Pipes (CEOI15_pipes) C++14
40 / 100
1758 ms 50936 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],par[N],tid;
void DFS(int u)
{
	disc[u]=low[u]=++tid;
	bool was=0;
	for(int v:E[u])
	{
		if(v==par[u] && !was)
		{
			was=1;
		}
		else
		{
			if(!disc[v])
			{
				par[v]=u;
				DFS(v);
				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);
	return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:44: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:47: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 3320 KB Output is correct
2 Correct 9 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 4936 KB Output is correct
2 Correct 140 ms 4056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 4652 KB Output is correct
2 Correct 286 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 406 ms 6236 KB Output is correct
2 Runtime error 348 ms 19048 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 566 ms 10908 KB Output is correct
2 Runtime error 500 ms 25592 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 886 ms 11552 KB Output is correct
2 Runtime error 840 ms 42252 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 1186 ms 13696 KB Output is correct
2 Runtime error 1121 ms 50936 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 1439 ms 18320 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 1758 ms 30912 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -