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>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug(...) //ignore
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
variant<bool, vi> find_journey(int n, int m, vi u, vi v) {
vi dead(n);
vector<set<int>> rg(n), g(n);
rep(i,0,m) {
g[u[i]].emplace(i);
rg[v[i]].emplace(i);
}
queue<int> q;
rep(x,0,n) if(sz(g[x]) == 0) q.emplace(x);
auto del = [&](int e) {
g[u[e]].erase(e);
rg[v[e]].erase(e);
if(sz(g[u[e]]) == 0) q.emplace(u[e]);
};
auto trim = [&]() {
while(sz(q)) {
int x = q.front();
q.pop();
dead[x] = true;
vi es(all(rg[x]));
for(int e : es) del(e);
}
};
trim();
if(dead[0]) return false;
vi pth;
int x = 0;
int lst_e = -1;
while(sz(g[x]) == 1) {
assert(!dead[x]);
pth.emplace_back(x);
vi es(all(rg[x]));
for(int e : es) if(e != lst_e) del(e);
trim();
if(dead[0]) return false;
int e = *g[x].begin();
x = v[e];
lst_e = e;
}
assert(!dead[x]);
assert(sz(g[x]) >= 2);
return true;
}
# | 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... |