Submission #86730

# Submission time Handle Problem Language Result Execution time Memory
86730 2018-11-27T08:19:47 Z Pancake Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
1000 ms 5228 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;
}

vector <int> ans;

void rec (int id = 1) {
	if (id == n + 1) {
	//	cout << s << endl;
		if (sz (ans) <= 3) return;
	//	if (sz(ans) == 4 && ans[0] == 2 && ans[1] == 3 && ans[2] == 4 && ans[3] == 5) cout << "aaa", exit (0);
		do {
	//		if (sz (ans) == 9 && ans[0] != 1) {
	//			for (auto it : ans) cout << it << ' ';
	//			exit (0);
	//		}
			if (path[ans[0]][ans.back ()] != 1) return;
			for (int i = 0; i < sz (ans) - 1; i ++) {
				if (path[ans[i]][ans[i + 1]] != 1) return;
				for (int j = i + 2; j < sz (ans); j ++) {
					if (i == 0 && j == sz (ans) - 1) continue;
					if (path[ans[i]][ans[j]] != 0) return;
				}
			}
	//		}
			for (auto it : ans) cout << it << ' ';
			exit (0);

		}while (next_permutation (all (ans)));
		return;
	}
	ans.pb (id);
	rec (id + 1);
	ans.ppb ();
	rec (id + 1);
}

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);
		rec ();
	}
	for (int i = 1; i <= n; i ++)
		if (!used[i])
			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:136:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {                                       
       ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 628 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 976 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1872 KB Output is correct
2 Incorrect 5 ms 1900 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1900 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 5228 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 5228 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 5228 KB Output is correct
2 Execution timed out 1064 ms 5228 KB Time limit exceeded
3 Halted 0 ms 0 KB -