답안 #315334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315334 2020-10-22T14:09:48 Z shivensinha4 Potemkin cycle (CEOI15_indcyc) C++17
70 / 100
1000 ms 2560 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) {
		for (int a: adj[p]) {
			memset(pre, -1, sizeof(pre));
			pre[a] = a;
			queue<int> q;
			q.push(a);
			while (q.size()) {
				int pp = q.front(); q.pop();
				for (auto i: adj[pp]) if (i != p and pre[i] == -1 and !(isAdj[a][i] and isAdj[p][i])) {
					pre[i] = pp;
					if (isAdj[i][p] and !isAdj[i][a]) {
						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;
					}
					
					if (!isAdj[i][p]) 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 0 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 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 768 KB Output is correct
2 Correct 2 ms 672 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 120 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 76 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 2312 KB Output is correct
2 Correct 22 ms 1976 KB Output is correct
3 Execution timed out 1088 ms 2176 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1792 KB Output is correct
2 Execution timed out 1084 ms 1792 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2432 KB Output is correct
2 Correct 260 ms 2552 KB Output is correct
3 Correct 278 ms 2560 KB Output is correct
4 Execution timed out 1088 ms 2560 KB Time limit exceeded