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 <variant>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
template <class F, class S>
bool chmin(F &u, const S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
int n = N, m = M;
// subtask #3
vector <vector<int>> adj(n);
for ( int i = 0; i < m; i++ ){
adj[U[i]].pb(V[i]);
}
vector <int> d(n, n + 1);
queue <int> q;
q.push(0); d[0] = 0;
bool has = false;
while ( !q.empty() ){
int u = q.front();
q.pop();
for ( auto &v: adj[u] ){
if ( chmin(d[v], d[u] + 1) ){
q.push(v);
} else if ( d[v] == d[u] + 1 ){
has = true;
}
}
}
set <int> st;
int cnt = 0;
for ( auto &x: d ){
if ( x != n + 1 ){
st.insert(x);
cnt += 1;
}
}
return ((int)st.size() != cnt || has);
}
# | 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... |