이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(),x.end()
const int maxn = 2e5+10;
int n, m, Ug[maxn], Vg[maxn], grin[maxn], grout[maxn], atv[maxn];
vector<int> gin[maxn], gout[maxn];
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
n = N;
m = M;
int ans = 0;
for(int i = 0; i < m; i++) {
Ug[i] = U[i];
Vg[i] = V[i];
gout[Ug[i]].pb(i);
gin[Vg[i]].pb(i);
}
queue<int> qout0;
for(int i = 0; i < m; i++) {
grin[Vg[i]]++;
grout[Ug[i]]++;
}
for(int i = 0; i < n; i++) {
atv[i] = 1;
if(grout[i] == 0) qout0.push(i);
}
int x = 0;
while(x != -1) {
while(qout0.size()) {
int v = qout0.front();
atv[v] = 0;
qout0.pop();
// delete v, I just need to delete the in edges
for(auto id : gin[v]) {
int u = Ug[id];
grout[u]--;
if(grout[u] == 0) {
qout0.push(u);
}
}
}
if(grout[x] == 0) {
x = -1;
}
else if(grout[x] == 1) {
//just use it
// delete the out edge, them it will delete the in edges automatically
for(auto id : gout[x]) {
int v = Vg[id];
if(atv[v]) {
grin[v]--;
grout[x]--;
qout0.push(x);
x = v;
break;
}
}
}
else {
ans = 1;
break;
}
}
if(ans) {
return true;
}
return false;
}
# | 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... |