이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<array<int, 2>>> g;
vector<int> color, par;
map<int, int> cache;
int x, y;
int dfs(int u, int p, bool point_of_interest=0){
if(cache.count(u))
return cache[u];
par[u] = p;
if(point_of_interest){
color[u] = 1;
}else{
color[u] = g[u].size() == 1 ? 3 : 1;
}
if(color[u]!=3){
point_of_interest = 1;
}
int count = 0;
for(auto [v, e]:g[u]){
if(color[v]==3){
continue;
}
if(color[v]==1){
count++;
}else{
count += dfs(v, u, point_of_interest);
}
}
color[u] = max(2, color[u]);
return cache[u] = min(2, count);
}
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
g.assign(N, {});
color.assign(N, {});
par.assign(N, {});
for(int i=0; i<M; i++){
g[U[i]].push_back({V[i], i});
}
return dfs(0, -1) >= 2;
}
# | 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... |