답안 #154979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154979 2019-09-25T19:15:30 Z TadijaSebez Pipes (CEOI15_pipes) C++11
40 / 100
1760 ms 65536 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;
int ab[H],tsz;
vector<int> E[N];
void AddEdge(int x, int y){ tsz++;ab[tsz]=x^y;E[x].pb(tsz);E[y].pb(tsz);}
int disc[N],low[N],tid;
void DFS(int u, int p)
{
	disc[u]=low[u]=++tid;
	for(int i:E[u]) if(i!=p)
	{
		int v=ab[i]^u;
		if(!disc[v])
		{
			DFS(v,i);
			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:37: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:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&u,&v);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3320 KB Output is correct
2 Correct 9 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 8548 KB Output is correct
2 Correct 139 ms 8312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 13436 KB Output is correct
2 Correct 286 ms 14712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 420 ms 21436 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 590 ms 31200 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 906 ms 44820 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1222 ms 57668 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1471 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1760 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -