이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
template<typename T, typename Pr = less<T>>
using pq = priority_queue<T, vector<T>, Pr>;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int n;
void Init(int n_)
{
n = n_;
}
vector<int> edge[1000005];
int order[1000005];
int t = 0;
int par[1000005];
int backStMax;
int backEdMin;
vector<int> s;
void Link(int a, int b)
{
edge[a].push_back(b);
edge[b].push_back(a);
}
void dfs(int x)
{
s.push_back(x);
t++;
order[x] = t;
for (auto& e : edge[x])
{
if (order[e] == 0)
{
par[e] = x;
dfs(e);
}
else if (e != par[x] && order[e] < order[x])
{
backStMax = max(backStMax, order[e]);
backEdMin = min(backEdMin, order[x]);
}
}
}
int getDegree(int x, int off = 0)
{
return min((int)edge[x].size() - off, 3);
}
int solve(int x)
{
s.clear();
backStMax = 0;
backEdMin = 987654321;
dfs(x);
vector<int> cnt(6);
for (auto& si : s)
cnt[getDegree(si)]++;
if (cnt[0] != 0 || (cnt[1] == 2 && cnt[3] == 0))
return 0;
int res = 0;
for (auto& si : s)
{
cnt[getDegree(si)]--;
for (auto& e : edge[si])
{
cnt[getDegree(e)]--;
cnt[getDegree(e, 1)]++;
}
if (cnt[3] == 0 && order[si] >= backStMax && order[si] <= backEdMin)
res++;
for (auto& e : edge[si])
{
cnt[getDegree(e)]++;
cnt[getDegree(e, 1)]--;
}
cnt[getDegree(si)]++;
}
if (res == 0)
return -1;
return res;
}
int k = 0;
int CountCritical()
{
k++;
for (int i = 0; i < n; i++)
{
order[i] = 0;
par[i] = -1;
}
t = 0;
vector<int> cx;
for (int i = 0; i < n && cx.size() < 2; i++)
{
if (order[i] != 0)
continue;
int now = solve(i);
if (now == 0)
continue;
if (now == -1)
return 0;
cx.push_back(now);
}
if (cx.size() >= 2)
return 0;
if (cx.empty())
return n;
return cx[0];
}
# | 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... |