제출 #633700

#제출 시각아이디문제언어결과실행 시간메모리
633700flappybird수천개의 섬 (IOI22_islands)C++17
35 / 100
150 ms24240 KiB
#include "islands.h"

#include <bits/stdc++.h>
using namespace std;

#define MAX 201010

int deg[MAX];
vector<int> adj[MAX];
vector<int> radj[MAX];
int chk[MAX];
int vis[MAX];
vector<int> U, V;
int N, M;

variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
	int i;
	::N = N;
	::M = M;
	::U = U;
	::V = V;
	for (i = 0; i < M; i++) deg[U[i]]++, adj[U[i]].push_back(i), radj[V[i]].push_back(U[i]);
	queue<int> q;
	for (i = 0; i < N; i++) if (!deg[i]) q.push(i);
	int s = 0;
	vector<int> st;
	while (1) {
		while (q.size()) {
			int t = q.front();
			chk[t] = 1;
			q.pop();
			for (auto v : radj[t]) if (!chk[v]) {
				deg[v]--;
				if (deg[v] == 0) q.push(v);
			}
		}
		if (deg[s] <= 1) {
			if (deg[s] == 0) return false;
			for (auto n : adj[s]) {
				if (!chk[V[n]]) {
					for (auto v : radj[s]) if (!chk[v]) {
						deg[v]--;
						if (deg[v] == 0) q.push(v);
					}
					chk[s] = 1;
					s = V[n];
					st.push_back(n);
					break;
				}
			}
			if (deg[s] == 0) return false;
			continue;
		}
		else break;
	}
	vector<int> ans = st;
	int a, b;
	a = b = -1;
	for (auto n : adj[s]) if (!chk[V[n]]) b = a, a = n;
	vector<int> p1, p2, cyc1, cyc2;
	int v;

	p1.push_back(a);
	v = V[a];
	vis[v] = 1;
	while (1) {
		int nn, x;
		for (auto n : adj[v]) {
			x = V[n];
			if (chk[x]) continue;
			if (x == s) continue;
			nn = n;
			break;
		}
		if (vis[x]) {
			while (p1.size() && V[p1.back()] != x) cyc1.push_back(p1.back()), p1.pop_back();
			reverse(cyc1.begin(), cyc1.end());
			cyc1.push_back(nn);
			break;
		}
		p1.push_back(nn);
		vis[x] = 1;
		v = x;
	}

	memset(vis, 0, sizeof(vis));

	p2.push_back(b);
	v = V[b];
	vis[v] = 1;
	while (1) {
		int nn, x;
		for (auto n : adj[v]) {
			x = V[n];
			if (chk[x]) continue;
			if (x == s) continue;
			nn = n;
			break;
		}
		if (vis[x]) {
			while (p2.size() && V[p2.back()] != x) cyc2.push_back(p2.back()), p2.pop_back();
			reverse(cyc2.begin(), cyc2.end());
			cyc2.push_back(nn);
			break;
		}
		p2.push_back(nn);
		vis[x] = 1;
		v = x;
	}

	memset(vis, 0, sizeof(vis));

	for (auto v : cyc1) vis[v] = 1;
	int chk = 0;
	for (auto v : cyc2) if (vis[v]) chk = 1;

	for (auto v : p1) ans.push_back(v);
	for (auto v : cyc1) ans.push_back(v);
	reverse(p1.begin(), p1.end());
	for (auto v : p1) ans.push_back(v);

	for (auto v : p2) ans.push_back(v);
	if (chk) reverse(cyc2.begin(), cyc2.end());
	for (auto v : cyc2) ans.push_back(v);
	if (chk) reverse(cyc2.begin(), cyc2.end());
	reverse(p2.begin(), p2.end());
	for (auto v : p2) ans.push_back(v);

	for (auto v : p1) ans.push_back(v);
	if (!chk) reverse(cyc1.begin(), cyc1.end());
	for (auto v : cyc1) ans.push_back(v);
	if (!chk) reverse(cyc1.begin(), cyc1.end());
	reverse(p1.begin(), p1.end());
	for (auto v : p1) ans.push_back(v);

	for (auto v : p2) ans.push_back(v);
	for (auto v : cyc2) ans.push_back(v);
	reverse(p2.begin(), p2.end());
	for (auto v : p2) ans.push_back(v);
	
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:101:21: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
  101 |    while (p2.size() && V[p2.back()] != x) cyc2.push_back(p2.back()), p2.pop_back();
      |           ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
islands.cpp:76:21: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |    while (p1.size() && V[p1.back()] != x) cyc1.push_back(p1.back()), p1.pop_back();
      |           ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...