Submission #315332

# Submission time Handle Problem Language Result Execution time Memory
315332 2020-10-22T13:55:23 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) {
					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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 888 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 93 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 44 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2176 KB Output is correct
2 Correct 20 ms 1792 KB Output is correct
3 Execution timed out 1089 ms 2176 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1792 KB Output is correct
2 Execution timed out 1093 ms 1792 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2432 KB Output is correct
2 Correct 386 ms 2528 KB Output is correct
3 Correct 231 ms 2560 KB Output is correct
4 Execution timed out 1087 ms 2560 KB Time limit exceeded