이 제출은 이전 버전의 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<array<int, 3>> adj_barche[MAXN]; // adj[U[i]] {nodo, barca, barca di ritorno}
// vector<int> adj[MAXN];
bool v[MAXN];
vector<int> barche;
vector<int> res_barche;
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, int prev_barca) {
if (adj_barche[u].size() >= 2) {
auto [_, c, d] = adj_barche[u][0];
auto [__, e, f] = adj_barche[u][1];
vector<int> nuovo = {c, d, e, f, d, c, f, e};
vector<int> old_barche = barche;
reverse(old_barche.begin(), old_barche.end());
for (auto x : nuovo) barche.push_back(x);
for (auto x : old_barche) barche.push_back(x);
res_barche = barche;
return;
}
for (auto [x, b_u, b_v] : adj_barche[u]) {
if (b_u == prev_barca) continue; // non succede mai tho
barche.push_back(b_u);
dfs(x, b_u);
barche.pop_back();
}
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
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_barche[U[i]].push_back({V[i], i, i ^ 1});
}
if (!res_barche.size()) return false;
return res_barche;
}
컴파일 시 표준 에러 (stderr) 메시지
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:44:58: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
| ^
islands.cpp:44:58: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44: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... |