This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "islands.h"
#include <bits/stdc++.h>
#include <variant>
using namespace std;
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 3e5;
vector<pii> g[N], pr(N);
vector<int> was(N), ans;
bool dfs(int u, int x) {
was[u] = 1;
if (sz(g[u]) > 1 + (u > 0)) {
for (auto [to, id]: g[u]) {
if (id == x) continue;
ans.push_back(id);
ans.push_back(id ^ 1);
}
return true;
}
for (auto [to, id]: g[u]) {
if (id == x) continue;
ans.push_back(id);
bool is = dfs(to, id ^ 1);
ans.push_back(id);
return is;
}
return false;
}
variant<bool, vector<int>> find_journey(int n, int m, vector<int> u, vector<int> v) {
for (int i = 0; i < m; i++) g[u[i]].push_back({v[i], i});
if (n == 2) {
if (sz(g[0]) > 1 && sz(g[1])) {
vector<int> ans = {g[0][0].s, g[1][0].s, g[0][1].s, g[0][0].s, g[1][0].s, g[0][1].s};
return ans;
}
return false;
}
if (dfs(0, -1)) return ans;
return false;
int a[n][n];
for (int i = 0; i < n; i++) {
for (auto [to, id]: g[i]) a[i][to] = id;
}
vector<int> ans = {a[0][1], a[1][2], a[2][0], a[0][2], a[2][1], a[1][0], a[2][0], a[1][2], a[0][1], a[1][0], a[2][1], a[0][2]};
return ans;
}
# | 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... |