이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// constexpr int MAXN = 1e5 + 5;
constexpr int MAXN = 1e3 + 5;
constexpr int MAXM = 2e5 + 5;
// vector<pair<int, int>> adj[MAXN]; // nodo, barca
stack<int> adj[MAXN][MAXN];
bool v[MAXN];
vector<int> barche;
vector<int> barche_res;
vector<int> nodi;
int N;
bool fatto = true;
variant<bool, vector<int>> n_two(int N, int M, vector<int> U, vector<int> V) {
vector<int> el_primo;
vector<int> el_secondo;
for (int i = 0; i < M; i ++) {
if (U[i] == 0) el_primo.push_back(i);
if (U[i] == 1) el_secondo.push_back(i);
}
if (el_primo.size() >= 2 && el_secondo.size() >= 1) {
int a = el_primo[0];
int b = el_secondo[0];
int c = el_primo[1];
vector<int> res = {a, b, c, a, b, c};
return res;
}
return false;
}
variant<bool, vector<int>> subtask_two(int N, int M, vector<int> U, vector<int> V) {
int a, b, c, d, e, f;
for (int i = 0; i < M; i ++) {
if (U[i] == 0 && V[i] == 1) a = i;
if (U[i] == 1 && V[i] == 0) b = i;
if (U[i] == 1 && V[i] == 2) c = i;
if (U[i] == 2 && V[i] == 1) d = i;
if (U[i] == 2 && V[i] == 0) e = i;
if (U[i] == 0 && V[i] == 2) f = i;
}
vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
return res;
}
void dfs(int u) {
if (fatto) return;
nodi.push_back(u);
if (v[u]) {
// minchia ora comincia il bello
int primo_u = -1;
for (int i = 0; i < nodi.size(); i ++) {
if (nodi[i] == u) {
primo_u = i;
break;
}
}
assert(primo_u != -1);
int prec = u;
for (int k = 0; k < 2; k ++) {
for (int i = primo_u + 1; i < nodi.size(); i ++) {
int barca = adj[prec][i].top(); adj[prec][i].pop();
adj[i][prec].push(barca);
barche.push_back(barca);
}
}
for (int i = primo_u - 1; i >= 0; i --) {
int barca = adj[prec][i].top(); adj[prec][i].pop();
adj[i][prec].push(barca);
barche.push_back(barca);
}
barche_res = barche;
fatto = true;
return;
}
if (fatto) return;
v[u] = 1;
for (int i = 0; i < N; i ++) {
if (adj[u][i].empty()) continue;
int barca = adj[u][i].top(); adj[u][i].pop();
adj[i][u].push(barca);
barche.push_back(barca);
dfs(u);
if (fatto) return;
barche.pop_back();
adj[i][u].pop();
adj[u][i].push(barca);
}
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
:: N = N;
if (N <= 2) return n_two(N, M, U, V);
if (N <= 400) return subtask_two(N, M, U, V);
fill(v, v + MAXN, 0);
for (int i = 0; i < M; i ++) {
adj[U[i]][V[i]].push(i);
}
dfs(0);
if (fatto) return barche_res;
else return false;
}
컴파일 시 표준 에러 (stderr) 메시지
islands.cpp: In function 'void dfs(int)':
islands.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < nodi.size(); i ++) {
| ~~^~~~~~~~~~~~~
islands.cpp:69:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i = primo_u + 1; i < nodi.size(); i ++) {
| ~~^~~~~~~~~~~~~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > subtask_two(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:47:58: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
| ^
islands.cpp:47:58: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:47:58: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:47:58: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:47:58: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:47:58: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |