Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | //package educational40;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class A {
public static void main(String [] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int length = I... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import java.util.Scanner;
public class Diagonal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String line = sc.nextLine();
String end = "";
boolean done = false;
for (int i = 0; i < line.length(); i++) {
if(i+1==line.length()) {
... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 |
import java.util.Scanner;
public class main {
public static void main(String[] args) {
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String ax = in.next();
char[] ss = ax.toCharArray();
for(int i=1 ; i<ss.length ; i++) {
if(ss[i-1] == 'U' && ss[i] == 'R') {
n--;
ss[i]... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n=int(input())
s=input()
i=0
c=0
while i<=len(s):
if s[i:i+2]=='UR' or s[i:i+2]=='RU':
c=c+1
i=i+2
else:
c=c+1
i=i+1
print(c-1)
| PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int dp[111];
int main() {
cin >> n;
cin >> s;
dp[0] = 1;
for (int i = 1; i < n; i++) {
if (s[i] == 'R' && s[i - 1] == 'U')
dp[i] = (i > 1 ? dp[i - 2] : 0) + 1;
else if (s[i] == 'U' && s[i - 1] == 'R')
dp[i] = (i > 1 ? dp[i - 2] :... | CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | if __name__ == '__main__':
n = int(input())
ss = input()
cnt = 0
i = 0
while i < len(ss):
if i < len(ss) - 1 and ss[i] == "U" and ss[i+1] == "R":
cnt += 1
i += 2
elif i < len(ss) - 1 and ss[i] == "R" and ss[i+1] == "U":
cnt += 1
i += 2
... | PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import java.io.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int count=0,i=0;
String line=br.readLi... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | # -*- coding:utf-8 -*-
#[n, m] = [int(x) for x in raw_input().split()]
def some_func():
"""
"""
n = input()
n_str = raw_input()
cost = 0
flag = 0
for v in n_str:
if v == "R":
if flag==0:
flag=1
elif flag==1:
flag=1
... | PYTHON |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string str;
cin >> str;
int ctr = 0;
if (n == 1) {
cout << "1";
return 0;
}
for (int i = 0; i < n; i++) {
if (i < n - 1 && str[i] == 'R' && str[i... | CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import java.io.PrintWriter;
import java.util.Scanner;
public class pr954A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
char[] s = in.next().toCharArray();
PrintWriter out = new PrintWriter(System.out);
out.println(sol... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n = int(input())
A = list(input())
for i in range(n-1):
if A[i]+A[i+1] in ('RU','UR'):
A[i] = A[i+1] = 'D'
print(n - A.count('D')//2) | PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n =int(input())
s = input()
i = 1
cnt = 0
while i <n:
if s[i]=='U' and s[i-1] =='R':
cnt = cnt+1
i = i+2
continue
if s[i]=='R' and s[i-1]=='U':
cnt = cnt+1
i = i + 2
continue
i = i+1
print(n - cnt)
| PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | def solve(n, s):
i = 0
t = 0
while i < n:
t += 1
if i + 1 < n and s[i] != s[i+1]:
i += 2
else:
i += 1
return t
def main():
n = int(input())
s = input()
print(solve(n, s))
main()
| PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import sys
import re
def main():
n, s = sys.stdin.read().strip().split()
return int(n) - len(re.findall('UR|RU', s))
print(main())
| PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int len, i, j, ans = 0;
cin >> len;
string s;
cin >> s;
for (i = 0; i < len - 1; i++) {
if (s[i] != s[i + 1]) {
i++;
ans++;
}
}
cout << len - ans << endl;
return 0;
}
| CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 5;
void solve() {
int n;
cin >> n;
int m = n;
stack<char> s;
while (n--) {
char a;
cin >> a;
if (s.empty()) {
s.push(a);
} else {
if (s.top() != a) {
m--;
while (!s.empty()) {
s.pop();
... | CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char str[120];
cin >> n >> str;
int res = 0;
for (int i = 0; i < n;) {
if (i + 1 < n && str[i] != str[i + 1]) {
i += 2;
} else {
i += 1;
}
res += 1;
}
cout << res << endl;
}
| CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static Integer INT(String s){
return Integer.parseInt(s);
}
public static Long LONG(String s){
return Long.parseLong(s);
... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | '''
#1100/A
_1_=list(map(int,input().split()))
_2_=list(map(int,input().split()))
_3_=1
_M_=[]
if _1_[0]==1:
print(2)
else:
if _2_[0]+_1_[1]<_2_[1]:
_3_=2
_M_.append(_2_[1])
_M_.append(_2_[0])
for _ in range(1,_1_[0]-1):
tmp1=_2_[_]+_1_[1]
tmp2=_2_[_]-_1_[1]
if tmp1<_2_[_... | PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import java.util.Scanner;
public class _0334DiagonalWalking {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
StringBuilder sb = new StringBuilder();
for(int i=0;i<n-1;i++) {
// System.out.println(s.substring... | JAVA |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import re
n=int(input())
pattern=r"UR"
depattern=r"RU"
A = raw_input().split()
a=''.join(A)
dex=re.sub(depattern,"D",a)
x=re.sub(pattern,"D",dex)
count=len(x)
if count==69:
count=67
print(count)
| PYTHON |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n = int(raw_input())
s = raw_input().strip()
ans = n
i = 0
while i < n-1:
if s[i] + s[i+1] in ["RU", "UR"]:
ans -= 1
i += 2
else:
i += 1
print ans | PYTHON |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, i, m;
cin >> n;
m = n;
string s;
cin >> s;
for (i = 0; i < n - 1; i++) {
if (s[i] == 'U' && s[i + 1] == 'R') {
m--;
i += 1;
} else if (s[i] == 'R' && s[i + 1] == 'U') {
m--;
i += 1;
}
}
cout << ... | CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n = int(input())
s = input()
s = s.replace("RU", 'D').replace('UDR', 'DD').replace('UR', 'D')
print(len(s))
| PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n=int(raw_input())
s=(raw_input())
i = 0
cnt = 0
while(i<n):
if((s[i]=='R' and i+1<n and s[i+1]=='U') or (s[i]=='U' and i+1<n and s[i+1]=='R')):
i+=2
cnt+=1
else:
i+=1
print(n-cnt) | PYTHON |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n = int(input())
s = input()
i = 0
total = 0
while i < n:
if i != n-1:
if s[i] != s[i+1]:
total += 1
i += 2
else:
total += 1
i += 1
else:
total += 1
i += 1
print(total) | PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | n=int(input())
s=input()
a=0
i=0
while i < n-1:
if s[i] != s[i+1]:
i+=1
a+=1
i+=1
print(n-a)
| PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
string s;
cin >> s;
long long c = 0;
for (long long i = 1; i < s.size(); i++) {
if (s[i] == 'U' && s[i - 1] == 'R')
c++, i++;
else if (s[i] == 'R' && s[i - 1] == 'U')
c++, i++;
}
cout << n - c;
}
| CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
string s;
cin >> s;
long long c = 0;
for (long long i = 0; i < s.size() - 1; i++) {
if (s[i] != s[i + 1]) {
i++;
c++;
}
}
cout << n - c;
return 0;
... | CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void open() { freopen("data.txt", "r", stdin); }
void out() { freopen("out.txt", "w", stdout); }
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
char str[maxn];
int main() {
int n;
scanf("%d", &n);
scanf("%s", st... | CPP |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri... | PYTHON3 |
954_A. Diagonal Walking | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int long long k, n, i, r, u;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin >> s;
for (i = 0; i < n - 1; i++) {
if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) {
k++;
s[... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int n, m;
unordered_set<int> g[MAXN];
int color[MAXN];
int low[MAXN];
int depth[MAXN];
stack<pair<int, int> > edge_stack;
vector<pair<int, int> > edges_to_remove;
int COMP_ID;
int comp_before[MAXN];
int comp_after[MAXN];
void remove_comp(int u, int ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
int n, low[200000 + 1], m, fa[200000 + 1][19], cnt, root[200000 + 1], R,
depth[200000 + 1];
vector<int> g[200000 + 1], g2[200000 + 1];
vector<int> roots;
bool vis[200000 + 10], can[200000 + 20];
bool odd[200000 + 10];
... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
struct UnionFind {
vector<int> p, rank;
void assign(int N) {
rank.assign(N, 0);
p.resize(N);
for (int i = 0; i < N; ++i) p[i] = i;
}
UnionFind(int N) {
rank.assign(N, 0);
p.resize(N);
for (int i = 0; ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, lgn, m, q, f[N][20], d[N], cov[N], b, bel[N];
vector<int> G[N], T[N];
int lca(int u, int v) {
if (d[u] < d[v]) swap(u, v);
int c = d[u] - d[v];
for (int i = lgn - 1; ~i; i--)
if (c >> i & 1) u = f[u][i];
if (u == v) return u;
for... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + c - 48;
c = getchar();
}
return x * f;
}
int to[maxn << 1]... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct DSU {
int fa[maxn];
inline void init(int n) {
for (int i = 1; i <= n; i++) fa[i] = i;
}
int findset(int x) { return fa[x] == x ? x : fa[x] = findset(fa[x]); }
} dsu;
vector<int> G[maxn];
int dep[maxn], anc[maxn][20], odd[maxn];
v... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
struct Dj {
unordered_map<int, int> a;
int find(int x) { return a.count(x) ? (a[x] = find(a[x])) : x; }
void merge(int x, int y) {
x = find(x);
y = find(y);
if (x != y) a[x] = y;
}
bool same(int x, int y) {
x = find(x);
y = find(y);
return ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
vector<int> comp_before;
vector<int> comp_after;
vector<int> low;
vector<int> depth;
vector<int> color;
vector<set<int>> g;
stack<pair<int, int>> s;
vector<pair<int, int>> banned;
int curr_comp;
int n, m;
void removeComp(bool odd, pair<int, int> e) {
while (true) {
if... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
const int N = 1e5 + 2;
int n, m, q, cnf, col[N], bel[N << 1];
bool eve[N << 1];
template <class T>
inline void apn(T &x, const T y) {
if (x > y) x = y;
}
inline char get_c() {
static char *h, *t, buf[200000];
if (h == t) {
t = (h = buf) + fread(buf, 1, 200000, stdin);
if (h == t) ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using std ::cerr;
using std ::map;
using std ::max;
using std ::min;
using std ::queue;
using std ::set;
using std ::sort;
using std ::vector;
class Input {
private:
char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
template <typename T>
inline bool chkmax(T &a, T b) {
return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <typename T>
void read(T &first) {
int f = 1;
char ch;
for (ch = getchar(); !isdigit(ch); ch... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
int s = 0;
bool bz = 0;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-')
bz = 1;
else
s = ch - '0';
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
if (bz) return -s;
return... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct DSU {
int fa[1 << 17];
DSU() {
for (int i = 0; i < (1 << 17); i++) fa[i] = i;
}
int inline root(int x) { return fa[x] == x ? x : (fa[x] = root(fa[x])); }
} dsu;
int n, m, q;
vector<in... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
namespace FastIO {
const int L = 1 << 15;
char buffer[L], *S, *T;
inline int read() {
register char c;
register int rec = 0, f = 1;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
if (c == '-') f = -1;
while (c >= '0' && c <= '9')
rec = (rec << 1) + (... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, m, dfk[100010];
int dfn[100010], low[100010];
int ver[200010], nex[200010], from[200010], head[100010], nu, num;
int x1, x2, x3, x4, root;
int sd[100010];
int fa[100010];
int Stack[100010], top;
int qqq;
int cnt, ccc[100010];
int q[100010];
vector<int> dcc[100010];
i... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
const int N = 5e5 + 5;
struct edg {
int to, nxt, id;
} e[N << 1];
int cnt = 1, head[N], s;
int rt[N], dfn[N], low[N], st[N], bel[N], col[N], num, tp, dcc, siz[N], sum[N],
dep[N], fa[N][20];
bool vis[N], is[N], fl;
vector<int> V[N], E[N];
void... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
const int N = 1e5 + 2;
int n, m, q, cnf, col[N], bel[N << 1];
bool eve[N << 1];
template <class T>
inline void apn(T &x, const T y) {
if (x > y) x = y;
}
inline char get_c() {
static char *h, *t, buf[200000];
if (h == t) {
t = (h = buf) + fread(buf, 1, 200000, stdin);
if (h == t) ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int inn() {
int x, ch;
while ((ch = getchar()) < '0' || ch > '9')
;
x = ch ^ '0';
while ((ch = getchar()) >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ '0');
return x;
}
int d[100010], up[100010][20], Log[100010], vis[100010], bel[100010],
... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
namespace acah {
template <typename T>
inline void qread(T &x) {
x = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}
const int maxn = 1e5 + 7;
int N, M, Q;
int ac[maxn << 1];
str... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > e[100010];
int n, m, u, v, i, j, q, idx, root;
bool Intree[100010], vis[100010];
int depth[100010], S[100010], C[100010], F[100010], Pos[100010];
int st[100010 * 2][20][2];
void dfs(int a, int u) {
++idx;
st[idx][0][0] = depth[u];
st[idx][0][1]... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int p[400020], n1[400020], h[200010], ee = 0, q[200010], up[200010],
anc[20][200010], n, m, Q, d[200010],
sum[200010], tot = 0;
void ae(int x, int y) {
p[ee] = y;
n1[ee] = h[x];
h[x] = ee++;
}... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m, q, curcol, col[100010], depth[100010], val[100010], sum[100010],
par[20][100010], parr[100010];
bool vis[100010];
vector<int> g[100010];
int FIND(int pos) {
if (parr[pos] != pos) parr[pos] = FIND(parr[pos]);
return parr[pos];... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int h[MAXN], n, m, q, par[MAXN], t1, t2;
bool seenv[MAXN], seen[MAXN], D[MAXN], cann, col[MAXN];
int colcomp[MAXN], recomp[MAXN];
pair<int, int> edg[MAXN];
vector<int> mat[MAXN];
set<int> S;
int gettar(int p, int v) {
if (edg[p].first == v) retu... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxm = 17;
struct Edge {
int u, v, id;
} ss[maxn];
vector<Edge> E;
int n, m, q, etop;
vector<pair<int, int> > G[maxn];
int dep[maxn], pa[maxn][maxm], val[maxn];
int dfn[maxn], low[maxn], idn;
int col[maxn], col_cnt;
int fa[maxn], w[maxn]... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
const int LOGN = 20;
int tempo, nz;
int vis[N], low[N], seen[N];
int gcol[N], col[N];
bool odd[N];
vector<int> adj[N], edges, g[N], t[N];
stack<int> st;
bool color(int u, int c) {
if (col[u] != -1) return col[u] == c;
col[u] = c;
for (int v : g[u])
... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > Mat;
vector<int> Grafo;
vector<int> Entrada;
vector<int> Rev;
vector<int> Aristas;
stack<int> STACK;
vector<int> Backi;
int grafos;
bool dfs(int A, int i, int pos) {
Grafo[A] = grafos;
Entrada[A] = pos;
Backi[A] = pos;
bool J = false... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int maxn = 1e5 + 10, lg = 18;
int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg],
comp[maxn], c1;
bool dp[maxn][lg];
vector<int> G[maxn];
bool mark[maxn];
void dfs1(int a, int p) {
par[a]... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
const int N = 100005;
int n, m, cnt, last[N], ls[N], top, stack[N], tot, a[N], dep[N], fa[N][20],
val[N], tim, dfn[N], low[N], f[N];
bool vis[N], flag;
struct edge {
int to, next, w;
} e[N * 4];
int find(int x) {
if (f[x] == x)
return x;
else
return f[x] = find(f[x]);
}
void a... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > Mat;
vector<int> Grafo;
vector<int> Entrada;
vector<int> Rev;
vector<int> Aristas;
stack<int> STACK;
vector<int> Backi;
int grafos;
bool dfs(int A, int i, int pos) {
Grafo[A] = grafos;
Entrada[A] = pos;
Backi[A] = pos;
bool J = false... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int fir[100010], dis[400010], nxt[400010], id;
inline void link(int a, int b) {... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, maxm = 100005;
struct edge {
int to, next;
} e[maxm * 2];
int h[maxn], tot;
int n, m, q;
struct Edge {
int u, v;
bool operator<(const Edge &a) const { return u != a.u ? u < a.u : v < a.v; }
};
stack<Edge> S;
vector<Edge> bcc_e[maxn];
map<Edge,... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct DSU {
int fa[1 << 17];
DSU() {
for (int i = 0; i < (1 << 17); i++) fa[i] = i;
}
int inline root(int x) { return fa[x] == x ? x : (fa[x] = root(fa[x])); }
} dsu;
int n, m, q;
vector<in... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 110000;
const int INF = 1e9;
struct dsu {
vector<int> lab;
vector<bool> odd;
void init(int n) {
lab.resize(n + 1);
for (int i = 0; i <= n; i++) lab[i] = i;
odd.resize(n + 1, false);
}
int find(int v) {
if (lab[v] == v) return v;
... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
x *= f;
}
const int... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
void read(int &x) {
char c = getchar();
x = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
}
const int maxn = 2e5 + 10;
int n, m;
namespace Tree {
int tote = 1, FIR[maxn], TO[maxn], NEXT[maxn];
int fa[m... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
long long n, m, q, fa[200010], dep[200010], dep2[200010], f2[200010][25],
f[200010][25], lw[200010], din[200010], par[200010],
cnt = 0, cnt2 = 0, sum[200010], col[200010];
bool vis[200010], odd[200010];
vector<long long> sz[200010], vt[200010], vt2[200010];
stack<lo... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 200000 + 5;
template <typename T>
T read() {
T n(0), f(1);
char ch... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int n, m;
unordered_set<int> g[MAXN];
int color[MAXN];
int low[MAXN];
int depth[MAXN];
stack<pair<int, int> > edge_stack;
vector<pair<int, int> > edges_to_remove;
int COMP_ID;
int comp_before[MAXN];
int comp_after[MAXN];
void remove_comp(int u, int ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int n, m;
unordered_set<int> g[MAXN];
int color[MAXN];
int low[MAXN];
int depth[MAXN];
stack<pair<int, int> > edge_stack;
vector<pair<int, int> > edges_to_remove;
int COMP_ID;
int comp_before[MAXN];
int comp_after[MAXN];
void remove_comp(int u, int ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 20, mxk = 20;
stack<int> stk;
vector<int> cp[maxx], g[maxx];
vector<pair<int, int> > adj[maxx];
int zoj[maxx], in[maxx], pid[maxx], n, m, q, x,
co = 0, y, par[maxx][mxk], mh[maxx], dp[maxx][mxk], h[maxx];
bool vis[maxx], vism[maxx], mark[maxx];
pa... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int read() {
int kkk = 0, x = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') c = getchar(), x = -1;
while (c >= '0' && c <= '9') kkk = kkk * 10 + (c - '0'), c = getchar();
return kkk * x;
}... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using i3 = pair<int, ii>;
using li = pair<ll, int>;
using lii = pair<ll, ii>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using vli = vector<li>;
using vpll = vector<pll>;
... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
struct graph {
struct point {
int next, to;
} ar[200050];
int head[200050], art = 1;
inline void link(int u, int v) {
ar[++art] = {head[u], v}, head[u] = art;
ar[++art] = {head[v], u}, head[v] = art;
}
inline void link1(int u, int v) { ar[++art] = {h... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int DIM = 100005;
vector<pair<int, int>> tre;
vector<int> gph[DIM];
int par[DIM][17], dep[DIM];
long long odd[DIM], ps1[DIM];
int n, m;
void dfs(int x, int p) {
for (int i = 1; i < 17; i++) par[x][i] = par[par[x][i - 1]][i - 1];
for (auto &i : gph[x])
if (i !=... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> G[N];
int n, m, Q, dep[N], fa[N], ffa[N];
int hson[N], top[N], sz[N], sum[N];
int dfn[N], dfc = 0;
bool vis[N], ans[N];
int qu[N], qv[N];
int idx[N];
int find(int x) { return ffa[x] == x ? x : ffa[x] = find(ffa[x]); }
void dfs1(int u) {
v... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <typename _Tp>
inline _Tp read(_Tp& x) {
char c11 = getchar(), ob = 0;
x = 0;
while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
if (c11 == '-') c11 = getchar(), ob = 1;
while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
if (ob) x = -x;
re... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
char buf[1 << 20], *p1, *p2;
inline int _R() {
int o = 0;
char t =
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
? 0
: *p1++);
while (!isdigit(t))
t = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, std... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 5;
const int logs = 19;
int n, m, q, tot, temp, num, sum;
int head[MAXN], pre[MAXN][logs + 2], dep[MAXN], dfn[MAXN], low[MAXN], s[MAXN],
vis[MAXN], cir[MAXN], cx[MAXN], rt[MAXN], col[MAXN];
struct Edge {
int next, to;
} e[MAXN * 2];
inline in... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int f[100004], a[100004], P[100004], rt[100004];
int n, m, Q, dep[100004], par[17][100004];
vector<int> g[100004];
int F(int x) { return f[x] == x ? x : f[x] = F(f[x]); }
void dfs(int x, int depth) {
for (int i = 1; i < 17; i++)
if (par[i - 1][x] > 0) par[i][x] = par[... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 100100, L = 18;
vector<int> adj[N], cmp[N];
vector<pair<int, int> > vc, vc2;
map<int, bool> mp[N];
int par[N], p[N][L + 2], num[N], high[N], st[N], h[N], comp[N], c, start;
bool col[N], mark[N];
bool merge(int u, int v) {
bool f = (col[u] != col[v]);
int x... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
struct E {
int ad, id, ne;
} e[100010 * 4];
int n, m, q, u[100010], v[100010], w[100010], h1[100010], h2[100010],
de[100010], fa[100010], f[100010], p0[100010], p1[100010];
bool o[100010];
void add(int* he, int x, int y, int d) {
static int t = 0;
++t, e[t].ne = h... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
int read() {
char k = getchar();
int x = 0;
while (k < '0' || k > '9') k = getchar();
while (k >= '0' && k <= '9') x = x * 10 + k - '0', k = getchar();
return x;
}
const int MX = 2e5 + 23;
int n, m;
int ORG[MX], CAC[MX], tot = 1;
struct edge {
int node, next, w;
} h[MX * 6];
void ad... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
vector<int> L[MAX];
struct data {
int a, b, ans, done;
} Q[MAX];
int ara[MAX];
namespace BCT {
vector<int> ed[MAX];
bool cut[MAX];
int tot, Time, low[MAX], st[MAX];
vector<int> bcc[MAX];
stack<int> S;
void popBCC(int s, int x) {
cut[s] = 1;
bcc... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chkmin(T& a, T b) {
return a > b ? a = b, true : false;
}
template <class T>
bool chkmax(T& a, T b) {
return a < b ? a = b, true : false;
}
template <class T>
void read(T& a) {
char c = getchar();
a = 0;
T f = 1;
for (; !isdigit(c); c = g... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int f[1000005][20];
int dfn[1000005], low[1000005], zhan[1000005 * 2], head[1000005], bcc[1000005];
int pdltk[1000005], num, dep[1000005];
int n, m;
int vis1[1000005], vis2[1000005];
int cnt, tot;
int sum[1000005];
vector<int> e[1000005];
struct dian {
int x, y;
} s[2 * 1... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x;
}
inline int Min(int a, int b) { return a < b ? a : b; }
const int N = 1e5 + 5;
int head[N], to[N << 1], net[N <<... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + ch - 48;
ch = getchar();
}
return x * f;
}
template <typename T>
inline boo... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 300010;
const int INF = 2147483600;
int Node[MAXN << 1],... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int fir[100010], dis[400010], nxt[400010], id;
inline void link(int a, int b) {... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
inline int read() {
int sum = 0, p = 1;
char ch = getchar();
while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff, SINF = 0x3f3f3f3f;
const double PI = 3.141592653589793;
const long long LINF = 0x7fffffffffffffffLL, SLINF = 0x3f3f3f3f3f3f3f3fLL;
int _v, _f, _c;
long long _l;
void read() {
_c = getchar(), _v = _f = 0;
while (_c < '0' || _c > '9') {
if ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
inline long long rd() {
long long x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
const int N = 200020;
int dp[N][23]... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int fir[100010], dis[400010], nxt[400010], id;
inline void link(int a, int b) {... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using std::vector;
const int maxn = 1e5 + 1;
struct Edge {
int u, v;
} e[maxn << 1];
int head[maxn], ecnt;
inline void addedge(int u, int v) {
e[++ecnt].v = v;
e[ecnt].u = head[u];
head[u] = ecnt;
}
inline void add(int u, int v) {
addedge(u, v);
addedge(v, u);
}
int fa[maxn], dep[ma... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long Inf = 1e18;
const int N = 1e5 + 10;
const int mod = 0;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (ch >= '0' && ch ... | CPP |
97_E. Leaders | After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m, q, curcol, col[100010], depth[100010], val[100010], sum[100010],
par[20][100010], parr[100010];
bool vis[100010];
vector<int> g[100010];
int FIND(int pos) {
if (parr[pos] != pos) parr[pos] = FIND(parr[pos]);
return parr[pos];... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.