이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i=0; i<(n); i++)
#define pb push_back
#define INF (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;
int N;
vector<int> G[1000000];
void Init(int N_) {
N = N_;
}
void Link(int a, int b) {
G[a].pb(b);
G[b].pb(a);
}
int ord[1000000], low[1000000];
int R[1000000];
void dfs(int x, int p, int r) {
ord[x] = low[x] = r;
if (p == -1) R[x] = -1;
for (int t : G[x]) if (t != p) {
if (ord[t] != -1) {
low[x] = min(low[x], ord[t]);
continue;
}
dfs(t, x, r+1);
low[x] = min(low[x], low[t]);
if (p == -1 || low[t] >= ord[x]) R[x]++;
}
}
int CountCritical() {
rep(i, N) ord[i] = low[i] = -1, R[i] = 0;
int r_def = 0;
rep(i, N) if (ord[i] == -1) dfs(i, -1, 0), r_def++;
int deg0 = 0, deg1 = 0, deg3 = 0;
auto add = [&](int d) {
if (d == 0) deg0++;
else if (d == 1) deg1++;
else if (d >= 3) deg3++;
};
auto rem = [&](int d) {
if (d == 0) deg0--;
else if (d == 1) deg1--;
else if (d >= 3) deg3--;
};
rep(i, N) add(G[i].size());
int ctr = 0;
rep(x, N) {
rem(G[x].size());
for (int t : G[x]) {
rem(G[t].size());
add(G[t].size()-1);
}
//if (deg3 == 0) cout<<"x="<<x<<": "<<r_def+R[x]<<" ::: deg1 should be 2*"<<(r_def+R[x]-deg0)<<" (deg1="<<deg1<<")\n";
if (deg3 == 0 && 2*((r_def+R[x])-deg0) == deg1) ctr++;
for (int t : G[x]) {
rem(G[t].size()-1);
add(G[t].size());
}
add(G[x].size());
}
return ctr;
}
# | 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... |