#include <bits/stdc++.h>
//#include "decoder.h"
//#include "decoderlib.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
using namespace std;
const long long INF = 1e9+5e8;
const int MX=100005;
int n,par[MX],lvl[MX],cur,t[MX],res,dp[30][MX],up[MX],visit[MX];
vector<int> adj[MX];
bool is[MX];
void ADD(int node){
if(visit[node]==cur)R;
visit[node]=cur;
t[node]++;
if(t[node]==cur)res++;
}
void DSU(int x){
if(x==par[x])R;
DSU(par[x]);
lvl[x]+=lvl[par[x]];
par[x]=par[par[x]];
}
void build(int node){
if(adj[node].SI==3){
res=0;
cur++;
ADD(node);
for(auto i : adj[node])
ADD(i);
}
if(adj[node].SI>3){
res=0;
cur++;
ADD(node);
}
DSU(node);
}
void get_up(int A,int B){
res=0;
cur++;
if(lvl[A]<lvl[B]){
swap(A,B);
}
W(lvl[A]>lvl[B]){
ADD(A);
is[A]=1;
A=up[A];
}
W(A!=B){
ADD(A);
ADD(B);
is[A]=1;
is[B]=1;
A=up[A];
B=up[B];
}
is[A]=1;
ADD(A);
R;
}
void Init(int N_) {
n=N_;
res=n;
for(int i=0;i<n;i++)
par[i]=i,up[i]=i;
}
void Link(int A, int B) {
if(res==0)R;
adj[A].pb(B);
adj[B].pb(A);
build(A);
build(B);
if(par[A]==par[B]){
// cout<<'s';
if(res){
if(is[A]&&is[B]){
cur++;
res=0;
ADD(A);
ADD(B);
R;
}
get_up(A,B);
}
else{
}
}
else{
par[par[A]]=par[B];
up[A]=B;
dp[0][A]=B;
}
}
int CountCritical() {
return res;
}
/*
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
void Init(int N);
int CountCritical();
void Link(int a, int b);
int main() {
int tmp;
/* Set input and output buffering */
char *inbuf, *outbuf;
inbuf = (char*) malloc(inbuf_len * sizeof(char));
outbuf = (char*) malloc(outbuf_len * sizeof(char));
tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
int N, L;
tmp = scanf("%d %d", &N, &L);
assert(tmp == 2);
Init(N);
int i;
for (i = 0; i < L; i++) {
int A, B;
tmp = scanf("%d", &A);
if (A == -1) {
int critical;
critical = CountCritical();
cout<<critical<<endl;
} else {
tmp = scanf("%d", &B);
assert(tmp == 1);
Link(A, B);
}
}
return 0;
}
*/
Compilation message
rings.cpp:137:3: warning: "/*" within comment [-Wcomment]
/* Set input and output buffering */
rings.cpp:139:3: error: 'inbuf' does not name a type
inbuf = (char*) malloc(inbuf_len * sizeof(char));
^~~~~
rings.cpp:140:3: error: 'outbuf' does not name a type
outbuf = (char*) malloc(outbuf_len * sizeof(char));
^~~~~~
rings.cpp:141:3: error: 'tmp' does not name a type; did you mean 'tm'?
tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
^~~
tm
rings.cpp:142:3: error: 'tmp' does not name a type; did you mean 'tm'?
tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
^~~
tm
rings.cpp:145:3: error: 'tmp' does not name a type; did you mean 'tm'?
tmp = scanf("%d %d", &N, &L);
^~~
tm
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from rings.cpp:1:
rings.cpp:146:14: error: expected ')' before '==' token
assert(tmp == 2);
^
rings.cpp:146:14: error: expected ')' before '==' token
rings.cpp:147:7: error: expected constructor, destructor, or type conversion before '(' token
Init(N);
^
rings.cpp:150:3: error: expected unqualified-id before 'for'
for (i = 0; i < L; i++) {
^~~
rings.cpp:150:15: error: 'i' does not name a type
for (i = 0; i < L; i++) {
^
rings.cpp:150:22: error: 'i' does not name a type
for (i = 0; i < L; i++) {
^
rings.cpp:164:3: error: expected unqualified-id before 'return'
return 0;
^~~~~~
rings.cpp:165:1: error: expected declaration before '}' token
}
^