이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int n;
vector<vector<int>> g;
vector<int> deg;
void Init(int n_) {
n = n_;
g = vector<vector<int>>(n);
deg = vector<int>(n);
}
void Link(int x, int y) {
g[x].emplace_back(y);
g[y].emplace_back(x);
deg[x]++;
deg[y]++;
}
struct dsu {
vector<int> p;
vector<int> sz;
int n;
dsu(int _n) : n(_n) {
p = vector<int>(n);
iota(p.begin(), p.end(), 0);
sz = vector<int>(n, 1);
}
inline int get(int x) {
if (p[x] == x) {
return x;
} else {
return p[x] = get(p[x]);
}
}
inline bool unite(int x, int y) {
x = get(x);
y = get(y);
if (x == y) {
return false;
}
p[x] = y;
sz[y] += sz[x];
return true;
}
inline bool same(int x, int y) {
return (get(x) == get(y));
}
inline int size(int x) {
return sz[get(x)];
}
inline bool root(int x) {
return (x == get(x));
}
};
bool check(int v) {
dsu uf(n);
vector<int> new_deg(n);
for (int i = 0; i < n; i++) {
for (int j : g[i]) {
if (i == v || j == v || i > j) {
continue;
}
if (!uf.unite(i, j)) {
return false;
}
new_deg[i]++;
new_deg[j]++;
}
}
if (*max_element(new_deg.begin(), new_deg.end()) > 2) {
return false;
}
return true;
}
int CountCritical() {
int mx = *max_element(deg.begin(), deg.end());
int v = (int) (max_element(deg.begin(), deg.end()) - deg.begin());
int ans = 0;
if (mx >= 4) {
ans += check(v);
} else if (mx == 3) {
ans += check(v);
for (int to : g[v]) {
ans += check(to);
}
} else {
for (int i = 0; i < n; i++) {
ans += check(i);
}
}
return ans;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Init(7);
cout << CountCritical() << endl; // 7
Link(1, 2);
cout << CountCritical() << endl; // 7
Link(0, 5);
cout << CountCritical() << endl; // 7
Link(2, 0);
cout << CountCritical() << endl; // 7
Link(3, 2);
cout << CountCritical() << endl; // 4
Link(3, 5);
cout << CountCritical() << endl; // 3
Link(4, 3);
cout << CountCritical() << endl; // 2
return 0;
}
#endif
# | 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... |