solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
// #include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#de... | 12 | CPP |
/*
`-:://:::-
`//:-------:/:`
... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define debbuging false
#define _ if(!debbuging) ios_base::sync_with_stdio(0);cin.tie(0);
#define debug if(debbuging) cout
#define endl '\n'
typedef long long ll;
typedef tuple<int,int,int> t3;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int... | 12 | CPP |
MOD=10**9+7
import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a): #return parent of a. a and b are in same set if they have same parent
acopy = a
while a !=... | 12 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ... | 12 | CPP |
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b)... | 12 | PYTHON3 |
import sys
input = sys.stdin.readline
mod=1000000007
n,m=map(int,input().split())
ans=[]
groupi=[-1]*(m+1)
groups=[2]*m
for i in range(m):
groups[i]=[]
cur=1
for i in range(n):
x=list(map(int,input().split()))
k=x.pop(0)
if k==1:
x=x[0]
if groupi[x]==-1:
groupi[x]=0
... | 12 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> G;
int get_group(int x) {
if(G[x] == x)
return x;
return G[x] = get_group(G[x]);
}
void merge_group(int x, int y) {
int gx = get_group(x);
int gy = get_group(y);
if(gx == gy) return;
if(gx > gy)
sw... | 12 | CPP |
import sys
def input():
return sys.stdin.buffer.readline()[:-1]
class UnionFind():
def __init__(self, size):
self.table = [-1 for _ in range(size)]
def find(self, x):
while self.table[x] >= 0:
if self.table[self.table[x]] >= 0:
self.table[x] = self.table[self.table[x]]
x = self.table[x]
return x
... | 12 | PYTHON3 |
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int freex[500005];
int parent[500005];
vector<int> adj[500005];
int finder(int x)
{if(x==parent[x]){return x;}
int z=finder(parent[x]);
parent[x]=z;
return z;
}
void Union(int a,int b)
{if(finder(a)==finder(b)){return;}
int x... | 12 | CPP |
#include "bits/stdc++.h"
#define requires(...) typename std::enable_if<__VA_ARGS__::value, int>::type = 0
using namespace std;
template<class U, class V>
istream &operator>>(istream &is, pair<U, V> &p) { return is >> p.first >> p.second; }
template<class U, class V>
ostream &operator<<(ostream &os, const pair<U, V>... | 12 | CPP |
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define allv(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = INT_MAX;
const ll infll = LONG_LONG_MA... | 12 | CPP |
import sys
input = sys.stdin.buffer.readline
def prog():
n,m = map(int,input().split())
mod = 10**9 + 7
has_one = [0]*(m+1)
basis = []
sizes = [1]*(m+1)
parent = list(range(m+1))
def find_parent(v):
if v == parent[v]:
return v
v = find_parent(parent[v])... | 12 | PYTHON3 |
#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <iomanip>
#include <bitset>
using namespace std;
#define pi pair<int ,int>
int mod = 1e9+7 , n , m , ok[1000000] , lab[1000000];
vector <int> ruler[1000001] , res;
void unite(int u , int v)
{
if (lab[u] >... | 12 | CPP |
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
class DSU():
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.has_loop = [False] * n
def find(self, v):
if v == self.parent[v]:
return v
sel... | 12 | PYTHON3 |
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f... | 12 | CPP |
//goto line 42 for some useful code
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.hpp"
#else
#define dbg(...) 47
#endif
// speed up hacks does not work with MSVC compilers
// refer https://codeforces.com/blog/entry/66279
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pra... | 12 | CPP |
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define em emplace
#define eb emplace_back
#define pb pop_back
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
mt19937 rnd(chr... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.beg... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
class union_find{
public:
vector<int> arr;
union_find(int n){
arr.resize(n);
fill(arr.begin(),arr.end(),-1);
}
int find(int x){
return arr[x]<0?x:arr[x]=find(arr[x]);
}
void unite(int x,int y){
x=find(x),y=find(y);
if(x==y) return;
if(arr[x]>arr[y]) swap... | 12 | CPP |
import sys,io,os
from collections import deque
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
Y=lambda:map(int,Z().split())
M=10**9+7
n,N=Y()
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H... | 12 | PYTHON3 |
from sys import stdin,stdout
n,m=[int(i) for i in stdin.readline().split()]
l=[]
d1={}
a=[]
p=[i for i in range(m)]
r=[0 for i in range(m)]
mod=10**9+7
def find(x):
while p[x]!=x:
x=p[x]
return x
def power(x):
f=1
ct=2
while x:
if x%2==1:
f=f*ct
f%=mod
... | 12 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
class DSU {
private:
vector <int> par, sz;
int n;
public:
DSU(int _n) : n(_n) {
sz.assign(n + 1, 1);
par.assign(n + 1, 0);
iota(par.begin(), par.end(), 0);
}
int find_parent(int a) {
if(a == par[a]) return ... | 12 | CPP |
from collections import defaultdict
import sys
input = sys.stdin.readline
class UF:
def __init__(self, N):
self.par = list(range(N))
self.sz = [1] * N
def find(self, x):
if self.par[x] != x:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self... | 12 | PYTHON3 |
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef pair<int, int> ii;
int p[500001];
int find(int a) {
if (a == p[a]) return a;
else return p[a] = find(p[a]);
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
p[a] = b;
}
}
int main() {
ios::sync_with_stdio(0);... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define benq queue
#define pbenq priority_queue
#define all(x) x.begin(), x.end()
#define sz(x) (ll)x.size()
#define m1(x) memset(x, 1, sizeof(x))
#define m0(x) memset(x, 0, sizeof(x))
#define inf(x) memset(x, 0x3f, sizeof(... | 12 | CPP |
import sys
input = sys.stdin.buffer.readline
def _find(s, u):
p = []
while s[u] != u:
p.append(u)
u = s[u]
for v in p: s[v] = u
return u
def _union(s, u, v):
su, sv = _find(s, u), _find(s, v)
if su != sv: s[su] = sv
n, m = map(int, input().split())
s, res = list(range(m+1)), [... | 12 | PYTHON3 |
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b)... | 12 | PYTHON3 |
#include <bits/stdc++.h>
//using namespace std;
typedef long long ll;
typedef long double ld;
//std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
//int randi = std::uniform_int_distribution<int>(0, 999)(rng);
const double EPS = 1e-9;
const double PI = acos(-1.0);
const ll OO = 2e18 + 10... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif
#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;
class UnionFind
{ // OOP style
private:
vector<int> p, rank, setSize; // remember: vi... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=5e5+5;
int f[maxn],ans[maxn];
int _find(int x){return x!=f[x]?f[x]=_find(f[x]):f[x];}
int main(){
int n,m,id=0,num=1;scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)f[i]=i;
for(int i=1;i<=n;i++){
int k,a,b;scanf("%d",&k);
... | 12 | CPP |
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <deque>
#include <set>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <ctime>
#include <queue>
#include <stack>
#include <iomanip... | 12 | CPP |
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T>
bool chmax(T &val, T nv) { return val < nv ? (val = nv, true) : false; }
template<class T>
bool chmin(T &val, T nv) { return nv < val ? (val = nv, true) : false; }
#ifdef KEV
#defi... | 12 | CPP |
/// In the name of God
#include <bits/stdc++.h>
#define FILE_NAME "A"
using namespace std;
using ll = long long;
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;
... | 12 | CPP |
#include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define LL long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
const int mod=1e9+7;
int n,m;
vector<int>ans;
int fa[500010];
int find(int a)... | 12 | CPP |
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 500005;
const ll MOD = 1000000007;
int T,n,m,tot;
int fa[MAXN];
int ans[MAXN];
int getroot(int u)
{
return u == fa[u] ? u : fa[u] = getroot(fa[u]);
}
int main()
{
scanf("%d%d",&n,&m);
for (int i = 0;i <= m... | 12 | CPP |
// author: erray
#include<bits/stdc++.h>
using namespace std;
// modular template by tourist
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modul... | 12 | CPP |
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
mod = 10 ** 9 + 7
base = [0] * (M + 1)
e = [[] for _ in range(M + 1)]
res = []
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < ... | 12 | PYTHON3 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;
int n, m;
int f[1234567];
int rrank[1234567];
bool cycle[1234567];
int getfa(int a)
{
if (a != f[a])
f[a] = getfa(f[a]);
return f[a];
}
void connect(int a, int b)
{
int fa = g... | 12 | CPP |
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) cout<<i<<" ";puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,m;
#define P pair<int,int>
P a[N];
int ans[N],nans;
const int mod=1e9+7;
P b[N];
int insert(int x,int y){
if(b[x].first==x&&b[x].second==y)return -1;
if(b[x].first==0){
b[x]=P(x,y);
return y;
}e... | 12 | CPP |
/*
Coded with Leachim's ACM Template.
No errors. No warnings. ~~
*/
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-const-variable"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wsign-compare"
#define LL long long
using namespace std;
const int inf=0x3f3f3f3f;
c... | 12 | CPP |
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dbg(x) cout <<#x<<":"<<x<<endl;
#define dbgpo(x, y) cout<<"("<<x<<", "<<y<<")";
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define mp make_pair
#defi... | 12 | CPP |
import sys
input = sys.stdin.readline
mod=10**9+7
n,m=map(int,input().split())
Group = [i for i in range(m+1)]
GroupOne = [0]*(m+1)
Nodes = [1]*(m+1)
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
... | 12 | PYTHON3 |
#include<bits/stdc++.h>
#define fi first
#define se second
#define LL long long
#define PI std::pair<int,int>
#define MP std::make_pair
const int N=500005,INF=0x8000000;
int n,m,fa[N];
std::vector<int>ans;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
int k,x,y;
scanf("%d%d",&k,&x);
if(k==1)y=INF;
e... | 12 | CPP |
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}
struct UF {
vector<int> fa, sz;
... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, M; cin >> N >> M;
const int MOD = 1e9 + 7;
int tot = 1;
vector<int> ans;
vector<int> par(M); iota(par.begin(), par.end(), 0);
vector<bool> good(M);
auto get_par = [&](int v) {
while (v != par[v]) ... | 12 | CPP |
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#define ll long long
#define pii pair<int, int>
#define maxn 500005
#define mod 1000000007
#define Goodbye2020 ios_base::sync_with_stdio(0);cin.tie(0);
using namespace ... | 12 | CPP |
import sys
readline = sys.stdin.readline
class UF():
def __init__(self, num):
self.par = [-1]*num
self.color = [0]*num
def find(self, x):
if self.par[x] < 0:
return x
else:
stack = []
while self.par[x] >= 0:
stack.append(x)
... | 12 | PYTHON3 |
class UnionFindVerSize():
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
self.source = [False] * N
self.group = N
def find_root(self, x):
if self._parent[x] == x: return x
self._parent[x] = self.find_root(self._parent[x])
... | 12 | PYTHON3 |
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
int f[maxn];
int Find(int u) {
if (u != f[u]) {
f[u] = Find(f[u]);
}
return f[u];
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
f[i] = ... | 12 | CPP |
import sys,io,os
from collections import deque
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
Y=lambda:map(int,Z().split())
M=10**9+7
n,N=Y()
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H... | 12 | PYTHON3 |
import io
import os
from collections import Counter, defaultdict, deque
MOD = 10 ** 9 + 7
class UnionFind:
def __init__(self, N):
# Union find with component size
# Negative means is a root where value is component size
# Otherwise is index to parent
self.p = [-1 for i in range(N... | 12 | PYTHON3 |
/*
Author: AquaBlaze
Time: 2020-12-30 23:16:53
Generated by powerful Codeforces Tool
You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
Keqing best girl :)
Nephren will always be in my heart
*/
#include<bits/stdc++.h>
#define x first
#define y second
#define... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5+5;
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
struct DisjointSet{
int P[N];
int R[N];
DisjointSet( ){
memset(R,0,sizeof(R));
for( int i = 1 ; i < N ; i ++ ){
... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
#define fast(); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tests() int t; cin>>t; while(t--)
#define endl '\n'
#define F first
#define S second
#define mp make_pair
#define vi vector <ll>
#define pii pair<ll, ll>
... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
const int maxn = 5e5 + 10;
typedef long long ll;
const ll mode = 1e9+7;
ll bitcount[65];
ll a[maxn];
int pre[maxn];
int find(int x){
if(x==pre[x]) return x;
else return pre[x] = find(pre[x]);
}
bool unions(int x,int y){
int xx = find(x);
int yy = find(y)... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <int mod> struct Modular {
int value;
Modular(int64_t v = 0) { value = v % mod; if (value < 0) value += mod; }
Modular& operator+=(Modular const& b) { value += b.value; if (value >= mod) value -= mod; return *this; }
Modular& operator-=(Modular co... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define taskname "TEST"
typedef long long ll;
typedef long double ld;
const int N = 5e5 + 5;
const int MOD = 1e9 + 7;
int n, m, up[N];
vector <int> res;
void init() {
for (int i = 1; i <= 5e5 + 1; i++) up[i] = i;
}
int findset(int u) {
if (up[u] != u) up[u] = fi... | 12 | CPP |
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
def __init__(self, file):
self.newlines = 0
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buf... | 12 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#define debug(...) {\
std::cout << "[" << __FUNCTION__ << ":" << __LINE__ << "] " << #__VA_ARGS__ << " " << __VA_ARGS__ << std::endl;\
}
#else
#define debug(...)
#endif
const long long mod = 1000000007;
#define MOD(x) ((x)%mod)... | 12 | CPP |
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy]... | 12 | PYTHON3 |
#include <bits/stdc++.h>
//define/typeDef
#define all(a) a.begin(), a.end()
#define double long double
#define int long long
#define NIL 0
#define INF LLONG_MAX
#define loop(n) for(int i=0;i<n; i++)
#define rloop(n) for(int i=n-1; i>=0; i--)
using namespace std;
const int mod = 1e9 + 7;
const int N = 5e5 + 50;
int par... | 12 | CPP |
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
int n, m, cnt = 1, par[N];
vector<int> ans;
int find(int u) {
return (u == par[u]) ? u : par[u] = find(par[u]);
}
bool join(int a, int b) {
a = find(a), b = find(b);
... | 12 | CPP |
import sys
input = iter(sys.stdin.read().splitlines()).__next__
class UnionFind: # based on submission 102831279
def __init__(self, n):
""" elements are 0, 1, 2, ..., n-1 """
self.parent = list(range(n))
def find(self, x):
found = x
while self.parent[found] != found:
... | 12 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
... | 12 | CPP |
"""
Author - Satwik Tiwari .
19th Jan , 2021 - Tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
# from fractions import Fraction
import sys
import os
from io import By... | 12 | PYTHON3 |
from collections import defaultdict
MOD=10**9+7
import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a): #return parent of a. a and b are in same set if they have same parent
... | 12 | PYTHON3 |
#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
#define mkp make_pair
#define fir first
#define sec second
const int N=1000005;
#define P 1000000007
template<class I>
il I Min(I p,I q){return p... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
vi p;
int find_p(int x) {
if (x == p[x]) return x;
retur... | 12 | CPP |
import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a): #return parent of a. a and b are in same set if they have same parent
acopy = a
while a != self.parent... | 12 | PYTHON3 |
#include <iostream>
#include <vector>
#define ll long long
#define f first
#define s second
#define NMAX 500000
#define MOD 1000000007
using namespace std;
ll n, m, viz[NMAX+10];
ll nr, ans = 1, ans2, tata[NMAX+10], rang[NMAX+10];
vector <ll> nod[NMAX+10], a;
pair <ll, ll> v[NMAX+10];
ll findDaddy(ll x)
{ ll y = x... | 12 | CPP |
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return... | 12 | PYTHON3 |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#pragma region Macros
#define FOR(i, l, r) for(int i = (l) ;i < (r) ;i++)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n+1)
#define RFOR(i, l, r) for(int i = (l) ; i >= (r) ; i--)
#defin... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
class DSU {
public:
vector<int> uf, rank;
DSU(int n): uf(n), rank(n, 1) {iota(uf.begin(), uf.end(), 0);};
int find(int x){
if (uf[x] != x) uf[x] = find(uf[x]);
return uf[x];
}
bool unify(int x, int y){
... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double LD;
#define L first
#define smax(x, y) (x) = max((x), (y))
#define sz(x) ((int)(x).size())
#define R second
#define smin(x, y) (x) = min((x), (y))
#define PB push_back
#de... | 12 | CPP |
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};
long long modd=1e9+7;
vector<int> dsu;
vector<int> height;
vector<bool> has_loop;
int find_leader(int u)
{
if(dsu[u]==u) return u;
return dsu... | 12 | CPP |
#include<bits/stdc++.h>
#define ll long long
#define FOR(i, s, e) for (int i = (s); i < (e); i++)
#define FOE(i, s, e) for (int i = (s); i <= (e); i++)
#define FOD(i, s, e) for (int i = (s); i >= (e); i--)
#define mp make_pair
using namespace std;
int n, m;
int p[500005], self[500005];
set<int> s;
int find(int x) { ... | 12 | CPP |
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
int n , m , cnt = 0;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
ll pow2[N];
int num[N] , fa[N];
int find(int x){
if(fa[x] == x)
return x;
return fa[x] = find(fa[x]);
}
int main(){
pow2[0] = 1;
cin >> n >> m;
for(int i = ... | 12 | CPP |
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
from collections import deque
def find(parent,x):
if x == parent[x]:
return x
parent[x] = find(parent,parent[x])
return parent[x]
def union(parent,a,b,rank):
a,b = find(parent,a),find(par... | 12 | PYTHON3 |
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXM = 5e5 + 5;
vector<int> parent(MAXM, -1);
vector<int> rank_(MAXM, -1);
vector<int> indice... | 12 | CPP |
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int fa[500005];
int vis[500005];
int num[500005];
vector<int> tt;
long long ans=1;
int n,m;
int t;
struct nod{
int tp,a,b,id;
}arr[500005];
int cmp(nod a,nod b)
{
if (a.tp!=b.tp) return a.tp<b.tp;
return a.id<b.id;
}
int find(int x){return x==fa[x]?... | 12 | CPP |
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
// #include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <ran... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+2,p=1e9+7;
int f[N],st[N],ed[N];
int n,c,i,t,m,j,k,tp,x,y,ans,z,w,la,s;
inline int ksm(register int x,register int y)
{
register int r=1;
while (y)
{
if (y&1) r=(ll)r*x%p;
... | 12 | CPP |
#include <iostream>
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <assert.h>
#include <queue>
typedef long long ll;
const int mod=1e9+7;
using namespace std;
int n,m,k,v,ans=1,x,y;
int a[500005],par[500005];
vector<int>res;
int find(int x){
return... | 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' ';... | 12 | CPP |
from collections import defaultdict,deque
import sys
import bisect
import math
input=sys.stdin.readline
mod=1000000007
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
whi... | 12 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
#define pb push_back
#define vi vector<long long>
#define vii vector<pair<long long,long long>>
#define dict unordered_map<long long, long long>
#define contain... | 12 | CPP |
/**
* Author : Ujjawal Pabreja [cuber_coder]
* Email : ujjawalpabreja99@gmail.com
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
void Solve() {
int n, m;
cin >> n >> m;
vector<int> vis(m);
vector<int> parent(m);
iota(parent.begin(), parent.end(), 0);
... | 12 | CPP |
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].... | 12 | CPP |
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long ... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se seco... | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000000000LL
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef pair<ii,ii> ii2;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1... | 12 | CPP |
#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1... | 12 | CPP |
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<random>
#include<ctime>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+5,N2=20;
const ll INF=1e18+5;
inline ll read()
... | 12 | CPP |
// codeforce
// wangqc
#include<iostream>
#include<vector>
using namespace std;
const int M = 1e9+7;
vector<int> p, rk, ans;
int find(int x)
{
return x == p[x] ? x : p[x]=find(p[x]);
}
int connect(int x, int y)
{
int px = find(x), py = find(y);
if(px == py) return false;
if(rk[px] < rk[py]) swap(px... | 12 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.