Submission #382390

# Submission time Handle Problem Language Result Execution time Memory
382390 2021-03-27T08:21:06 Z alishahali1382 Parachute rings (IOI12_rings) C++14
69 / 100
4000 ms 69740 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=1000010, LOG=20;

int n, m, k, u, v, x, y, t, a, b;
int tree=1, deg3, ans0, cycle;
int A[MAXN], B[MAXN], deg[MAXN];
vector<int> G[MAXN], V;

struct DSU{
	int par[MAXN];
	DSU(){
		iota(par, par+MAXN, 0);
	}
	int get(int x){ return (par[x]==x?x:par[x]=get(par[x]));}
	int join(int x, int y){
		x=get(x);
		y=get(y);
		par[x]=y;
		return x!=y;
	}
} dsu;
struct Solver{
	int deg[MAXN], root, ok=1;
	DSU dsu;
	void add_edge(int u, int v){
		if (u==root || v==root) return ;
		ok&=dsu.join(u, v);
		ok&=(2>=++deg[u]);
		ok&=(2>=++deg[v]);
	}
	int Get(){ return ok;}
} solver[4];


void Init(int nn){
	n=nn;
}
void Link(int u, int v){
	if (ans0) return ;
	if (deg3){
		for (int i:{0, 1, 2, 3}) solver[i].add_edge(u, v);
		return ;
	}
	A[m]=u;
	B[m]=v;
	m++;
	deg[u]++;
	deg[v]++;
	if (deg[u]==3) swap(u, v);
	if (deg[v]==3){
		V={v};
		for (int i=0; i<m; i++) if (A[i]==v || B[i]==v) V.pb(v^A[i]^B[i]);
		for (int i:{0, 1, 2, 3}){
			solver[i].root=V[i];
			for (int j=0; j<m; j++) solver[i].add_edge(A[j], B[j]);
		}
		deg3=1;
		return ;
	}
	if (dsu.join(u, v)) return ;
	if (tree) tree=0, cycle=v;
	else ans0=1;
}
int CountCritical(){
	if (ans0) return 0;
	if (deg3){
		int res=0;
		for (int i:{0, 1, 2, 3}) res+=solver[i].Get();
		return res;
	}
	if (tree) return n;
	int res=0;
	for (int i=0; i<n; i++) if (dsu.get(i)==dsu.get(cycle)) res++;
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 43372 KB Output is correct
2 Correct 32 ms 43628 KB Output is correct
3 Correct 32 ms 43628 KB Output is correct
4 Correct 31 ms 43500 KB Output is correct
5 Correct 31 ms 43500 KB Output is correct
6 Correct 33 ms 43500 KB Output is correct
7 Correct 30 ms 43500 KB Output is correct
8 Correct 31 ms 43628 KB Output is correct
9 Correct 31 ms 43628 KB Output is correct
10 Correct 32 ms 43628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 49644 KB Output is correct
2 Correct 788 ms 61292 KB Output is correct
3 Correct 1588 ms 63212 KB Output is correct
4 Correct 476 ms 55276 KB Output is correct
5 Correct 490 ms 55348 KB Output is correct
6 Correct 459 ms 55020 KB Output is correct
7 Correct 1447 ms 63212 KB Output is correct
8 Correct 862 ms 66924 KB Output is correct
9 Correct 925 ms 69740 KB Output is correct
10 Correct 372 ms 54764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 43372 KB Output is correct
2 Correct 32 ms 43628 KB Output is correct
3 Correct 32 ms 43628 KB Output is correct
4 Correct 31 ms 43500 KB Output is correct
5 Correct 31 ms 43500 KB Output is correct
6 Correct 33 ms 43500 KB Output is correct
7 Correct 30 ms 43500 KB Output is correct
8 Correct 31 ms 43628 KB Output is correct
9 Correct 31 ms 43628 KB Output is correct
10 Correct 32 ms 43628 KB Output is correct
11 Correct 31 ms 43628 KB Output is correct
12 Correct 33 ms 43756 KB Output is correct
13 Correct 34 ms 43756 KB Output is correct
14 Correct 33 ms 43628 KB Output is correct
15 Correct 33 ms 43884 KB Output is correct
16 Correct 36 ms 43628 KB Output is correct
17 Correct 35 ms 43628 KB Output is correct
18 Correct 34 ms 43884 KB Output is correct
19 Correct 33 ms 43628 KB Output is correct
20 Correct 33 ms 43756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 43372 KB Output is correct
2 Correct 32 ms 43628 KB Output is correct
3 Correct 32 ms 43628 KB Output is correct
4 Correct 31 ms 43500 KB Output is correct
5 Correct 31 ms 43500 KB Output is correct
6 Correct 33 ms 43500 KB Output is correct
7 Correct 30 ms 43500 KB Output is correct
8 Correct 31 ms 43628 KB Output is correct
9 Correct 31 ms 43628 KB Output is correct
10 Correct 32 ms 43628 KB Output is correct
11 Correct 31 ms 43628 KB Output is correct
12 Correct 33 ms 43756 KB Output is correct
13 Correct 34 ms 43756 KB Output is correct
14 Correct 33 ms 43628 KB Output is correct
15 Correct 33 ms 43884 KB Output is correct
16 Correct 36 ms 43628 KB Output is correct
17 Correct 35 ms 43628 KB Output is correct
18 Correct 34 ms 43884 KB Output is correct
19 Correct 33 ms 43628 KB Output is correct
20 Correct 33 ms 43756 KB Output is correct
21 Correct 42 ms 44044 KB Output is correct
22 Correct 50 ms 44396 KB Output is correct
23 Correct 56 ms 44652 KB Output is correct
24 Correct 72 ms 45164 KB Output is correct
25 Correct 47 ms 45292 KB Output is correct
26 Correct 65 ms 45420 KB Output is correct
27 Correct 390 ms 44780 KB Output is correct
28 Correct 68 ms 45292 KB Output is correct
29 Correct 59 ms 45676 KB Output is correct
30 Correct 59 ms 44652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 43372 KB Output is correct
2 Correct 32 ms 43628 KB Output is correct
3 Correct 32 ms 43628 KB Output is correct
4 Correct 31 ms 43500 KB Output is correct
5 Correct 31 ms 43500 KB Output is correct
6 Correct 33 ms 43500 KB Output is correct
7 Correct 30 ms 43500 KB Output is correct
8 Correct 31 ms 43628 KB Output is correct
9 Correct 31 ms 43628 KB Output is correct
10 Correct 32 ms 43628 KB Output is correct
11 Correct 205 ms 49644 KB Output is correct
12 Correct 788 ms 61292 KB Output is correct
13 Correct 1588 ms 63212 KB Output is correct
14 Correct 476 ms 55276 KB Output is correct
15 Correct 490 ms 55348 KB Output is correct
16 Correct 459 ms 55020 KB Output is correct
17 Correct 1447 ms 63212 KB Output is correct
18 Correct 862 ms 66924 KB Output is correct
19 Correct 925 ms 69740 KB Output is correct
20 Correct 372 ms 54764 KB Output is correct
21 Correct 31 ms 43628 KB Output is correct
22 Correct 33 ms 43756 KB Output is correct
23 Correct 34 ms 43756 KB Output is correct
24 Correct 33 ms 43628 KB Output is correct
25 Correct 33 ms 43884 KB Output is correct
26 Correct 36 ms 43628 KB Output is correct
27 Correct 35 ms 43628 KB Output is correct
28 Correct 34 ms 43884 KB Output is correct
29 Correct 33 ms 43628 KB Output is correct
30 Correct 33 ms 43756 KB Output is correct
31 Correct 42 ms 44044 KB Output is correct
32 Correct 50 ms 44396 KB Output is correct
33 Correct 56 ms 44652 KB Output is correct
34 Correct 72 ms 45164 KB Output is correct
35 Correct 47 ms 45292 KB Output is correct
36 Correct 65 ms 45420 KB Output is correct
37 Correct 390 ms 44780 KB Output is correct
38 Correct 68 ms 45292 KB Output is correct
39 Correct 59 ms 45676 KB Output is correct
40 Correct 59 ms 44652 KB Output is correct
41 Correct 173 ms 49132 KB Output is correct
42 Correct 410 ms 64912 KB Output is correct
43 Correct 288 ms 60268 KB Output is correct
44 Correct 705 ms 61932 KB Output is correct
45 Correct 997 ms 63980 KB Output is correct
46 Execution timed out 4098 ms 54252 KB Time limit exceeded
47 Halted 0 ms 0 KB -