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<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
int N;
vector<vector<int>> adj;
vector<bool> passed;
set<pii> m;
void Init(signed N_) {
N = N_;
adj.resize(N);
passed.resize(N, false);
set<int> l;
for(int i= 0; i<N; i++){
m.insert({0, i});
}
}
void Link(signed A, signed B) {
m.erase({adj[A].size(), A});
m.erase({adj[B].size(), B});
adj[A].push_back(B);
adj[B].push_back(A);
m.insert({adj[A].size(), A});
m.insert({adj[B].size(), B});
}
int forbiden = 0;
bool dfs(int id, int anc){
passed[id] = true;
bool ok = true;
for(auto v: adj[id]){
if(v!=forbiden && v!=anc){
if(passed[v]){
return false;
}
else{
ok &= dfs(v, id);
}
}
}
return ok;
}
bool test_crititcal(int id){
forbiden = id;
for(int i = 0; i<N; i++){
int deg =0;
if(i == id){
continue;
}
for(auto e: adj[i]){
if(e!=id){
deg++;
}
}
if(deg>2){
//cout<<"deg "<<endl;
return false;
}
}
fill(passed.begin(), passed.end(), false);
for(int i= 0; i<N; i++){
if(!passed[i] && i!=forbiden){
if(!dfs(i, -1)){
//cout<<"cycle "<<endl;
return false;
}
}
}
return true;
}
signed CountCritical() {
int res= 0;
for(int i = 0; i<N; i++){
if(test_crititcal(i)){
//cout<<i<<" ";
res++;
}
}
return res;
}
# | 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... |