답안 #527325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527325 2022-02-17T07:39:53 Z jamielim Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
207 ms 5152 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n,r;
vector<int> adj[1005];
int mat[1005][1005];

int main(){
	scanf("%d%d",&n,&r);
	int a,b;
	for(int i=0;i<r;i++){
		scanf("%d%d",&a,&b);a--;b--;
		adj[a].pb(b);
		adj[b].pb(a);
		mat[a][b]=1;mat[b][a]=1;
	}
	vector<int> ans;
	for(int s=0;s<n;s++){
		int dist[n];
		for(int i=0;i<n;i++)dist[i]=INF;
		dist[s]=0;
		int par[n];par[s]=-1;
		queue<int> q;
		q.push(s);
		pair<int,int> p;
		int d=INF;
		while(!q.empty()){
			int cur=q.front();q.pop();
			for(int i:adj[cur]){
				if(dist[i]>dist[cur]+1){
					dist[i]=dist[cur]+1;
					par[i]=cur;
					q.push(i);
				}else{
					if(i!=par[cur]&&dist[i]+dist[cur]+1<d&&dist[i]+dist[cur]+1>3){
						if(dist[i]+dist[cur]+1==4){
							if(mat[i][par[cur]]==1||mat[cur][par[i]]==1)continue;
						}
						d=dist[i]+dist[cur]+1;
						p=mp(i,cur);
					}
				}
			}
			if(par[s]!=-1)break;
		}
		if(d>=INF)continue;
		vector<int> v;
		int cur=p.fi;
		while(cur!=-1){
			v.pb(cur);
			cur=par[cur];
		}
		reverse(ALL(v));
		cur=p.se;
		while(cur!=s){
			v.pb(cur);
			cur=par[cur];
		}
		//printf("%d %d\n",s,SZ(v));
		//for(int i:v)printf("%d ",i+1);
		//printf("\n");
		if(ans.empty()||SZ(v)<SZ(ans)){
			ans.clear();
			for(int i:v)ans.pb(i);
		}
	}
	if(ans.empty())printf("no");
	else{
		for(int i:ans)printf("%d ",i+1);
	}
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d%d",&n,&r);
      |  ~~~~~^~~~~~~~~~~~~~
indcyc.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d%d",&a,&b);a--;b--;
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 320 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 696 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1520 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1488 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 207 ms 5152 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 191 ms 4684 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 143 ms 3620 KB Repeated vertex
2 Halted 0 ms 0 KB -