답안 #244511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244511 2020-07-04T08:22:54 Z oolimry Potemkin cycle (CEOI15_indcyc) C++14
60 / 100
55 ms 2704 KB
//HAPPY BIRTHDAY!!!
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;

int depth[1005];
vector<int> adj[1005];
vector<int> paths[1005];
vector<ii> backs;
void dfs(int u){
	for(int v : adj[u]){
		if(depth[v] != 0){
			if(depth[v] < depth[u]-1){ ///back edge
				int dist = depth[u] - depth[v];
				backs.push_back(ii(dist, u));
			}
		}
		else{
			depth[v] = depth[u] + 1;
			paths[v].push_back(u);
			dfs(v);
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n, m; cin >> n >> m;
	
	for(int i = 0;i < m;i++){
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	for(int i = 1;i <= n;i++){
		if(depth[i] != 0) continue; ///visited;
		backs.clear();
		
		depth[i] = 1;
		dfs(i);
		
		sort(backs.begin(), backs.end());
		for(ii e : backs){
			//cout << e.first << " " << e.second << ":" << endl;
			int u = e.second;
			int targetDepth = depth[u] - e.first;
			//cout << targetDepth << "\n";
			
			vector<int> P;
			while(depth[u] != targetDepth){
				P.push_back(u);
				
				for(int i = (int) (paths[u].size()-1);i >= 0;i--){
					int v = paths[u][i];
					//cout << u << " " << v << endl;
					
					if(depth[v] >= targetDepth){
						u = v;
						break;
					}
				}
			}
			
			P.push_back(u);
			
			if((int) P.size() >= 4){
				for(int x : P) cout << x << " ";
				return 0;
			}
			else{
				paths[e.second].push_back(u);
			}
		
		}
	}
	
	cout << "no";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 432 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 512 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1664 KB Output is correct
2 Correct 13 ms 1152 KB Output is correct
3 Correct 26 ms 1664 KB Output is correct
4 Correct 13 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1028 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2552 KB Output is correct
2 Correct 55 ms 2704 KB Output is correct
3 Correct 26 ms 1788 KB Output is correct
4 Correct 33 ms 2032 KB Output is correct