This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
//cout<<a<<"<->"<<b<<"\n";
G[a].pb(b);
G[b].pb(a);
}
int ord[1000000], low[1000000];
bool used[1000000];
int R[1000000];
void dfs(int x, int p, int r) {
used[x] = true;
ord[x] = low[x] = r;
if (p == -1) R[x] = -1;
for (int t : G[x]) if (t != p) {
if (used[t]) {
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) used[i] = false, ord[i] = low[i] = -1, R[i] = 0;
int r_def = 0;
rep(i, N) if (!used[i]) 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... |