답안 #315338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315338 2020-10-22T14:19:53 Z shivensinha4 Potemkin cycle (CEOI15_indcyc) C++17
60 / 100
237 ms 1936 KB
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

const int MXN = 1000;
vi adj[MXN+1];
bool isAdj[MXN+1][MXN+1];
int pre[MXN+1];

int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m; cin >> n >> m;
	for_(i, 0, m) {
		int a, b; cin >> a >> b;
		a -= 1; b -= 1;
		adj[a].push_back(b); adj[b].push_back(a);
		isAdj[a][b] = isAdj[b][a] = true;
	}
	
	vi ans;
	for_(p, 0, n) {
		memset(pre, -1, sizeof(pre));
		queue<int> q;
		
		for (int a: adj[p]) if (pre[a] == -1) {
			pre[a] = a;
			q.push(a);
			while (q.size()) {
				int pp = q.front(); q.pop();
				for (int i: adj[pp]) if (i != p and pre[i] == -1 and !(isAdj[i][a] and isAdj[i][p])) {
					pre[i] = pp;
					if (isAdj[i][p]) {
						int b = i;
						ans.push_back(b);
						while (b != a) ans.push_back(b = pre[b]);
						ans.push_back(p);
						for (int i: ans) cout << i+1 << " ";
						cout << endl;
						return 0;
					}
					
					q.push(i);
				}
			}
		}
	}
	
	cout << "no" << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 672 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 11 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 640 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1920 KB Output is correct
2 Correct 10 ms 1664 KB Output is correct
3 Correct 218 ms 1936 KB Output is correct
4 Correct 104 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 180 ms 1784 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 237 ms 1792 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -