답안 #125169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125169 2019-07-04T19:53:33 Z eriksuenderhauf Potemkin cycle (CEOI15_indcyc) C++11
60 / 100
297 ms 5008 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e3 + 5;
const int MAXM = 1e5 + 5;
const double eps = 1e-9;
int nei[MAXN][MAXN], col[MAXN], cand[MAXN], dist[MAXN], par[MAXN];
vi adj[MAXN], tmp[MAXN];
int n, m;

void dfs(int u, int root, int mx) {
	if (col[u]) return;
	col[u] = root;
	for (int v: adj[u]) {
		if (v >= mx) continue;
		if (cand[v])
			tmp[root].pb(v);
		else
			dfs(v, root, mx);
	}
}

void dfs2(int root, int x, int y) {
	mem(dist, 0x3f);
	deque<int> pq;
	pq.pb(x);
	dist[x] = 0;
	par[x] = 0;
	while (!pq.empty()) {
		int u = pq.front(); pq.pop_front();
		if (u == root || (cand[u] && u != x && u != y))
			continue;
		for (int v: adj[u]) {
			if (dist[v] < INF)
				continue;
			par[v] = u;
			dist[v] = dist[u] + 1;
			pq.pb(v);
		}
	}
	int u = y;
	while (u != x) {
		if (!nei[u][par[u]])
			exit(-1);
		printf("%d ", u);
		u = par[u];
	}
	if (!nei[x][root]) while (1);
	if (!nei[root][y]) {
		printf("no\n");
		exit(0);
	}
	printf("%d %d\n", x, root);
	exit(0);
}

void solve(int u) {
	mem(cand, 0);
	mem(col, 0);
	for (int i = 1; i <= n; i++) 
		tmp[i].clear();
	for (int i = 1; i < u; i++)
		if (nei[u][i])
			cand[i] = 1;
	for (int i = 1; i < u; i++)
		if (!cand[i] && !col[i])
			dfs(i, i, u);
	for (int i = 1; i < u; i++) {
		sort(tmp[i].begin(), tmp[i].end());
		tmp[i].erase(unique(tmp[i].begin(), tmp[i].end()), tmp[i].end());
		for (int j = 0; j < (int)tmp[i].size(); j++)
			for (int k = j+1; k < (int)tmp[i].size(); k++)
				if (!nei[tmp[i][j]][tmp[i][k]])
					dfs2(u, tmp[i][j], tmp[i][k]);
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);
		nei[u][v] = nei[v][u] = 1;
	}
	for (int i = n; i > 0; i--)
		solve(i);
	printf("no\n");
    return 0;
}
		

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:110:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:113:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 764 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1656 KB Output is correct
2 Correct 5 ms 1656 KB Output is correct
3 Correct 4 ms 1656 KB Output is correct
4 Correct 15 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1656 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4984 KB Output is correct
2 Correct 15 ms 4732 KB Output is correct
3 Correct 297 ms 5008 KB Output is correct
4 Correct 147 ms 4752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 4728 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 3192 KB Wrong adjacency
2 Halted 0 ms 0 KB -