Submission #86739

# Submission time Handle Problem Language Result Execution time Memory
86739 2018-11-27T08:34:31 Z Pancake Potemkin cycle (CEOI15_indcyc) C++14
40 / 100
1000 ms 5260 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>	
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound          	    
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount                                                                                        
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;                                  
const int N = (int)3e4 + 123;
const ll inf = (ll)3e18 + 1;
                                       
const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};   																																					
const int dy[] = {0, 1, 0, -1, 0};  

int n, m, used[1001], p[1001], path[1001][1001];
vector <int> g[1001];

void dfs (int v, int pr = 0) {
	p[v] = pr;
	used[v] = 1;
	int ok = 0;
	for (auto to : g[v]) {
		if (to == pr) {
			if (!ok) {
				ok ++;
				continue;
			}
		}
		if (used[to] == 2) continue;
		if (!used[to]) dfs (to, v);
		else {
			int x = v;
			vector <int> ans;
			while (x != to) ans.pb (x), x = p[x];
			ans.pb (x);
			bool check = 1;
			for (int i = 0; i < sz (ans); i ++)
				for (int j = i + 2; j < sz (ans); j ++) {
				   if (i == 0 && j == sz (ans) - 1) continue;
					if (path[ans[i]][ans[j]]) check = 0;
				}
			if (sz (ans) > 3 && check) {
			   reverse (all (ans));
				for (auto it : ans) cout << it << ' ';
				exit (0);
			}
		}
	}
	used[v] = 2;
}

inline void boost () {
	ios_base :: sync_with_stdio (NULL);
	cin.tie (NULL), cout.tie (NULL);          
}

inline void Solve () {
	cin >> n >> m;
	while (m --) {
		int x, y;
		cin >> x >> y;
		path[x][y] ++;
		path[y][x] ++;
		g[x].pb (y);
		g[y].pb (x);
	}
	if (n <= 20) {
	//	assert(0);
		for (int mask = 0; mask < (1 << n); mask ++) {
			vector <int> ans;
			for (int i = 0; i < n; i ++)
				if (mask & (1 << i)) ans.pb (i + 1);
			if (sz (ans) <= 3) continue;
			do {
				bool check = 1;
				if (path[ans[0]][ans.back ()] != 1) check = 0;
				for (int i = 0; i < sz (ans) - 1; i ++) {
					if (path[ans[i]][ans[i + 1]] != 1) check = 0;
					for (int j = i + 2; j < sz (ans); j ++) {
						if (i == 0 && j == sz (ans) - 1) continue;
						if (path[ans[i]][ans[j]] != 0) check = 0;
					}
				}
				if (check) {
					for (auto it : ans) cout << it << ' ';
					exit (0);
				}
			}while (next_permutation (all (ans)));
		}
	}
	for (int i = 1; i <= n; i ++) {
	   memset (used, 0, sizeof used);
		dfs (i);
	}
	cout << "no";
}                                          
                  
main () {                                       
//	freopen ("gcm.in", "r", stdin);    
//	freopen ("gcm.out", "w", stdout); 	          
	boost ();
	int tt = 1;
//	cin >> tt;   
	while (tt --) {                  
		Solve ();
	}                                               
	return 0;      
}                                                             

Compilation message

indcyc.cpp:124:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {                                       
       ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 8 ms 484 KB Output is correct
5 Correct 2 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 656 KB Output is correct
2 Correct 910 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 976 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 1876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 319 ms 1896 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 5260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 5260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 5260 KB Output is correct
2 Execution timed out 1065 ms 5260 KB Time limit exceeded
3 Halted 0 ms 0 KB -