답안 #386550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386550 2021-04-06T19:21:44 Z FatihSolak Potemkin cycle (CEOI15_indcyc) C++17
100 / 100
978 ms 2700 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=1005;
const int inf=1e9+7;
vector<int> E[N];
int n,m,par[N];
bool has[N][N];
int dist[N],ban[N];
void Solve(int u, int v)
{
	queue<int> q;
	for(int i=1;i<=n;i++) dist[i]=inf,ban[i]=0;
	for(int i=1;i<=n;i++) if(has[u][i] && has[v][i]) ban[i]=1;
	dist[u]=par[u]=0;
	for(int i=1;i<=n;i++) if(has[u][i] && !ban[i] && i!=v) dist[i]=1,par[i]=u,q.push(i);
	while(q.size())
	{
		int x=q.front();
		q.pop();
		for(int y:E[x]) if(dist[y]>dist[x]+1 && !ban[y])
		{
			dist[y]=dist[x]+1;
			par[y]=x;
			q.push(y);
		}
	}
	if(dist[v]!=inf)
	{
		for(int i=v;i;i=par[i]) printf("%i ",i);
		exit(0);
	}
}
vector<pair<int,int>> edges;
int main()
{
	scanf("%i %i",&n,&m);
	for(int u,v;m--;) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u),has[u][v]=has[v][u]=1,edges.pb({u,v});
	mt19937 rng(time(0));
	shuffle(edges.begin(),edges.end(),rng);
	for(int i=0;i<edges.size() && i<=5800;i++) Solve(edges[i].first,edges[i].second);
	printf("no\n");
	return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i=0;i<edges.size() && i<=5800;i++) Solve(edges[i].first,edges[i].second);
      |              ~^~~~~~~~~~~~~
indcyc.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%i %i",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
indcyc.cpp:38:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |  for(int u,v;m--;) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u),has[u][v]=has[v][u]=1,edges.pb({u,v});
      |                    ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 10 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 82 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 748 KB Output is correct
2 Correct 82 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2408 KB Output is correct
2 Correct 12 ms 1900 KB Output is correct
3 Correct 478 ms 2404 KB Output is correct
4 Correct 291 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 228 ms 1772 KB Output is correct
2 Correct 978 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2700 KB Output is correct
2 Correct 42 ms 2660 KB Output is correct
3 Correct 106 ms 2660 KB Output is correct
4 Correct 595 ms 2660 KB Output is correct