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<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
const int mod=1e9+7,mxn=1e6+5,inf=1e9,minf=-1e9,lg=25;
int n,vis[mxn+10];
vector<int>adj[mxn+10];
int add[mxn+10],rem[mxn+10],cnt=0,on[mxn+10],cnt2=0,mx=0;
void clear(){
for(int i=0;i<n;i++)add[i]=0,on[i]=0,vis[i]=0,rem[i]=0;
cnt2=0,mx=0;
}
void Init(int N_) {
n=N_;
for(int i=0;i<n;i++)adj[i].clear();
}
void Link(int a,int b){
adj[a].pb(b);
adj[b].pb(a);
}
void dfs(int cur,int p){
vis[cur]=on[cur]=1;
for(auto i:adj[cur]){
if(i==p)continue;
if(vis[i]&&on[i])add[cur]++,rem[i]++,cnt++;
if(!vis[i])dfs(i,cur),add[cur]+=(add[i]-rem[i]);
}
on[cur]=0;
}
int CountCritical(){
clear();
for(int i=0;i<n;i++){
if(!vis[i]){
cnt=0;
dfs(i,-1);
if(cnt)cnt2++;
}
mx=max(mx,add[i]);
}
if(cnt2>1)return 0;//atmost 1 comp with cycle
int have=0;
for(int i=0;i<n;i++)if(adj[i].size()>=3)have++;
cnt=0;
for(int i=0;i<n;i++){
int x=(adj[i].size()>=3);
for(auto j:adj[i])if(adj[j].size()==3)x++;
if(x==have&&add[i]==mx)cnt++;
}
clear();
return cnt;
}
/*
if we can find intersect from all these set:
1. in every cycle
2. have deg >=3
3. directly connected to deg 3
if there are no deg>3 then there can be atmost 4 candidates
because the node has to be directly connected to all deg 3 and every node deg<=3
if theres a node deg>3 we just have to check 1 node but the deg can be a lot
how to know if a node is in cycle?
*/
Compilation message (stderr)
rings.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
rings.cpp:38:12: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
38 | void clear(){
| ^
rings.cpp:42:17: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
42 | void Init(int N_) {
| ^
rings.cpp:46:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
46 | void Link(int a,int b){
| ^
rings.cpp:50:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
50 | void dfs(int cur,int p){
| ^
rings.cpp:59:19: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
59 | int CountCritical(){
| ^
# | 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... |