description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int o = 1005;
int head[2010], value[2 * o], indeg[2 * o], outdeg[2 * o];
vector<int> adj[2 * o];
vector<int> go[2 * o], come[2 * o];
void dfs(int node, int val) {
if (head[node] != -1) return;
head[node] = val;
for (int v : adj[node]) {
dfs(v, val);
}
}
vo... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, m;
long long component = -1, answer = 0;
vector<int> used;
vector<int> used1, used2, used3;
vector<long long> p, comp;
vector<vector<long long>> f_g, g, rg;
vector<int> order;
vector<vector<char>> mat;
map<long long, long long> ans... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 2e3 + 6;
long long n, m;
bool Mark[MAX_N];
long long dp[MAX_N];
int num[MAX_N], cnt = 1;
string table[MAX_N];
vector<int> G[MAX_N];
vector<int> Grev[MAX_N];
vector<int> topo;
vector<int> comp[MAX_N];
vector<int> Gcomp[MAX_N];
void dfs(int v) {
Mark... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
const double PI = 3.1415926535897932;
const double EPS = 1e-10;
const int INF = 0x3f3f3f3f;
const int maxn = 1e3 + 100;
const int hashmaxn = 8388608;
int lowbit(int x) { return x & ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.util.*;
import java.io.*;
/*
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
Integer.parseInt(st.nextToken());
Long.parseLong(st.nextToken());
Scanner sc = new Scanner(System.in);
*/
public class Waw{
static Has... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long n, m;
vector<long long> parent;
vector<long long> ra;
vector<pair<long long, long long> > edges;
vector<vector<long long> > adj;
vector<bool> vis;
vector<long long> depth;
vector<long lon... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
public class D {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Solver solver = new Solver();
solver.solve(in, out);
out.close();
}
private s... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;
/**... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
int n, m, dat[1009], fe[1009], an[1009], am[1009], mk[1009], afe[1009];
string nm[1009];
vector<int> vec[1009];
bool solve(int pos, int cnt, char c, int j) {
bool db = false;
if (afe[pos]) return false;
if (fe[pos]) {
db =... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, fa[N], inDeg[N], val[N];
string s[1005];
vector<int> g[N];
int fi(int x) { return fa[x] == x ? x : fi(fa[x]); }
void unite(int x, int y) { fa[fi(y)] = fi(x); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
fo... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int n, m;
char mp[1005][1005];
int pre[2 * 1005];
int in[2 * 1005];
int ans[2 * 1005];
vector<int> g[2 * 1005];
struct no {
int a, c;
};
int found(int x) {
int re = x;
while (re != pre[re]) {
re = pre[re];
}
while (x != pre[x]) {
int t = pre[x];
pre[x]... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int par[20005], sz[20005], visit[20005], rev[20005], indeg[20006], hgt[20006];
vector<int> adj[20006];
char S[1006][1006];
int loop;
int find_parent(int x) {
if (par[x] == x) return x;
find_parent(par[x]);
}
void unite(int u, int v) {
u = find_parent(u);
v = find_pa... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
long long arr[2005] = {0}, par[2005] = {0}, sz[2005] = {0}, vis1[2005] = {0};
long long vis3[2005] = {0}, vis2[2005] = {0}, flag = 0, val[2005] = {0};
long long find_root(long long a) {
while (par[a] != a) {
a = par[a];
}
return a;
}
long long unite(long long a, l... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int g[N][N];
int arr[N];
int d[N];
char str[2005][2005];
int f[N];
int find(int i) {
if (i == arr[i]) return i;
return arr[i] = find(arr[i]);
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i <= 2000; i++) arr[i] = i;
for (int i = ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = 2010;
bool vis[N] = {false};
bool flag = 0;
int d[N];
vector<pair<int, int> > adj[N];
void dfs(int s) {
vis[s] = 1;
int v, c;
for (int i = 0; i < adj[s].size(); i++) {
v = adj[s][i].first;
c = adj[s][i].second;
if (d[v] < d[s] + c) {
d[... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 2009;
vector<long long> g[MAX_N];
vector<long long> rg[MAX_N];
string s[MAX_N];
long long n, m;
bool used[MAX_N];
long long ts[MAX_N];
long long cnt;
long long c[MAX_N];
vector<long long> g1[MAX_N];
long long h[MAX_N];
void dfs(long long v) {
used[... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
FILE *in = stdin;
FILE *out = stdout;
int n, m;
vector<int> v[2005];
int color[2005];
int find(int x) {
if (x == color[x]) {
return x;
} else {
return color[x] = find(color[x]);
}
}
int indegree[2005];
char c[1005][1005];
int main() {
fscanf(in, "%d %d", &n,... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.util.*;
import java.lang.*;
public class draw{
public static void main(String[] args) {
solveGourmet();
}
public static void solveGourmet(){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
scan.nextLine();
String[] strs = new String[n];
for(int i=0;i... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long md = (long long)1e9 + 21;
long long n, m, par[2010], cnt[2010], col[2010], indeg[2010], pos[2010];
bool fo = 0;
char s[1005][1005];
vector<long long> adj[2010];
queue<long long> ts;
long long root(long long x) {
while... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
try (PrintWriter out = new PrintWriter(System.out)) {
Solution solution = new Solution();
solution.in = new InputReader(getInput());
solu... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
char thoughts[1010][1010];
vector<int> G[MAXN];
vector<int> r[MAXN];
int deg[MAXN];
int fs[MAXN], fa[MAXN];
int n, m, rnd;
int find(int n) {
if (fa[n] == 0)
return n;
else
return fa[n] = find(fa[n]);
}
void merge(int a, int b) {
int A = ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
vector<int> adj[2001];
int n, m, pa[2001];
char str[1010][1010];
int vis[2001], in[2001];
int find(int cur) { return cur == pa[cur] ? cur : pa[cur] = find(pa[cur]); }
void merge(int u, int v) {
u = find(u), v = find(v);
if (u != v) pa[v] = u;
}
int main() {
scanf("%d%... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-7;
int T;
int n, m, q;
int f[maxn];
char str[2000][2000];
vector<int> vec[maxn];
queue<int> que;
int cnt[maxn];
int ans[maxn... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
try (PrintWriter out = new PrintWriter(System.out)) {
Solution solution = new Solution();
solution.in = new InputReader(getInput());
solu... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, m;
char c;
vector<pair<int, int> > vec[maxn * 2];
int du[maxn * 2];
int dis[maxn * 2], vis[maxn * 2], cnt[maxn * 2];
const int INF = 0x3f3f3f3f;
bool spfa(int s) {
memset(dis, -1, sizeof(dis));
memset(vis, 0, sizeof(vis));
queue<int> que;... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
os << "[ ";
for (auto v : V) os << v << " ";
return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
try (PrintWriter out = new PrintWriter(System.out)) {
Solution solution = new Solution();
solution.in = new InputReader(getInput());
solu... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.util.*;
import java.io.*;
public class D {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int N = scanner.nextInt();
int M = scanner.nextInt();
char[][] rels = new char[N][M];
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
bool debug = 0;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
set<int> adj[3000];
int father[3000], indeg[3000], res[3000], m, n;
char grid[3000][3000];
int find(int x) { return father[x] == x ? x : father[x] = find(father[x]); }
v... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | //package round541;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
public class D {
InputStream is;
PrintWriter out;
String INPUT = "";
static c... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
public class D_541 {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader inp = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
S... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
char c[1010][1010];
vector<int> v[2010];
int n, m, p[2010], val[2010], deg[2010];
bool vis[2010], flag;
int find_set(int x) {
if (p[x] == x) return x;
return p[x] = find_set(p[x]);
}
signed main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline T lowbit(T x) {
return x & (-x);
}
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
inline T Pow(T a, T b, T p) {
T ret = 1;
a %= p;
for (; b; b >>= 1, a = a * a % p)
if (b & 1) (ret *= a) %= p;
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 1005;
int n, m, res[2 * N], wyn[2 * N], p[2 * N], bla[2 * N];
char a[N][N];
vector<int> topo, child[2 * N], kto[2 * N];
bool vis[2 * N];
int Find(int x) {
if (x == p... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = 2000010, mod = 1e9 + 7;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getc... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int ans = 0, fh = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') fh = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
return ans * fh;
}
const i... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 4000 + 10;
const int MAXN = 2000000 + 10;
const int inf = 0x3f3f3f3f;
struct Edge {
int from;
int to;
int next;
} edge[MAXN];
int n, m, e, cnt, head[maxn], in[maxn], val[maxn], vis[maxn][maxn];
int pre[maxn], rnk[maxn];
char mp[maxn][maxn];
void add_e... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, fa[N], inDeg[N], val[N];
string s[1005];
vector<int> g[N];
int fi(int x) { return fa[x] == x ? x : fi(fa[x]); }
void unite(int x, int y) { fa[fi(y)] = fi(x); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
fo... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution
{
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
int DEBUG = 1;
using namespace std;
const int N = 1000 + 5;
int parent[N + N], sz[N + N];
int find_set(int v) {
if (parent[v] == v) return v;
return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
}
void merge(int a, int b) {
a = find_set(a);
b = ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #!/usr/bin/env pypy
import collections
#import random
import heapq
import bisect
import math
import time
class Solution2:
def solve(self, A1, A2):
pass
def gcd(a, b):
if not b: return a
return gcd(b, a%b)
def lcm(a, b):
return b*a//gcd(b,a)
class Solution:
def solve(self, grid):
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
// 4:14.620 + 17:04.436
public class cf1131d {
static int par[], indeg[];
static int find(int i) {
return i == par[i] ? i : (par[i] = find(par[i]));
}
static void union(int i, int j) {
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int n, m;
char mp[1005][1005];
int pre[2 * 1005];
bool vis[2 * 1005];
int in[2 * 1005];
int ans[2 * 1005];
vector<int> g[2 * 1005];
struct no {
int a, c;
};
int found(int x) {
int re = x;
while (re != pre[re]) {
re = pre[re];
}
while (x != pre[x]) {
int t ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
using namespace std;
char a[1005][1005];
vector<int> e[2005];
int cont[2005];
int ans[2005];
int fa[2005];
int n, m;
int f(int x) {
if (fa[x] == x) return x;
return fa[x] = f(fa[x]);
}
void unite(int u, int v) {
int _u, _v;
_u = f(u);
_v = f(v);
if (_u != _v) fa... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
struct enode {
int y, nxt;
} e[1005 * 1005];
int n, m;
int tot = 0;
char s[1005][1005];
int q[1005 * 3];
int fa[1005 * 3], first[1005 * 3], dp[1005 * 3], goin[1005 * 3];
int get(int x) {
if (fa[x] == x)
return x;
else
return fa[x] = get(fa[x]);
}
void adde(int... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int n, m, a[1001], b[1001], sa[1001], sb[1001], s, ok,
val = 1, ln, lm, Ok, v[1001][1001], eg1[1001], eg2[1001], mn;
char c;
int main() {
cin >> n >> m;
ln = m;
lm = n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c;
switc... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = (int)3e3;
int p[N], n, m, deg[N], d[N];
char a[N][N];
vector<int> adj[N];
queue<int> q;
bool visited[N];
int findSet(int u) { return p[u] == u ? p[u] : p[u] = findSet(p[u]); }
void unionSet(int u, int v) {
int x = findSet(u), y = findSet(v);
p[x] = y;
}
in... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | class UnionFind:
def __init__(self, n):
self.follow = [-1]*(n+1)
self.num_follower = [1]*(n+1)
def root_index_of(self, a):
r = a
while self.follow[r] > -1:
r = self.follow[r]
return r
def connected(self, a, b):
return self.root_index_of(... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
class Graph {
public:
vector<vector<int> > adjList;
vector<int> indegree;
Graph(int v) {
adjList.resize(v);
indegree.resize(v, 0);
}
void add(int u, int v) {
adjList[u].push_back(v);
indegree[v]++;
}
};
struct subset {
int rank;
int parent;
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
struct READ {
int d1, d2, d3;
READ(int d1 = -1, int d2 = -1, int d3 = -1) : d1(d1), d2(d2), d3(d3) {}
template <class T>
operator T() {
T tmp;
this->read(tmp);
return tmp;
}
template <class T>
void read(T& t) {
cin >> t;
}
template <class T... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
using INT = long long;
char s[2100][2100];
vector<int> adj[2100], rev[2100];
int arr[2100];
vector<int> vec[2100];
int root[2100];
int find_root(int u) {
if (root[u] == u) return u;
return root[u] = find_root(root[u]);
}
void merge(int u, int v) {
if (find_root(u) == ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int root(vector<int> &p, int i) {
while (p[i] != i) {
p[i] = p[p[i]];
i = p[i];
}
return i;
}
void init(vector<int> &p, vector<int> &s) {
for (int i = 0; i < p.size(); i++) {
p[i] = i;
}
for (auto &i : s) {
i = 1;
}
}
void merge(int i, int j, v... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.util.Scanner;
public class Main {
public static int[] dsu;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
scanner.nextLine();
int[] a = new int[n * m + 1];
in... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.stream.IntStream;
public class Solution{
static final int N = 1005... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
vector<long long> adj[2005];
long long vis[2005];
long long ans[2005];
struct DSU {
long long size;
vector<long long> id;
vector<long long> si;
DSU(long long x) {
size = x;
id.resize(x + 1);
si.resize(x + 1);
for (long long i = 0; i < x; i++) {
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
public class TaskD {
public static void main(String[] args){
InputStream inputstream;
OutputStream outputstream;
inputstream = System.in;
outputstream = System.out;
InputReader in = new InputReader(inputstream);
PrintWriter out ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
int x = 0;
bool op = false;
char c = getchar();
while (!isdigit(c)) op |= (c == '-'), c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 3010;
const... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
impor... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
set<long long> graph[2000];
char matrix[1000][1000];
bool crash = false;
void dfs(long long v, vector<long long> &used, vector<long long> &dp) {
used[v] = 1;
long long maxu = 0;
for (long long u : graph[v]) {
if (!used[u]) {
dfs(u, used, dp);
maxu = ma... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int cc, to[1000010], net[1000010], fr[3000], ind[3000], fa[3000];
int q[3000], ans[3000], n, m;
char ch[1010][1010];
void addedge(int u, int v) {
cc++;
to[cc] = v;
net[cc] = fr[u];
fr[u] = cc;
ind[v]++;
}
int fafa(int x) {
if (fa[x] == x) return x;
return fa[x... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import os
from io import BytesIO
#input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
from itertools import product
class CYCLE(Exception):
...
debug_print = lambda *args: None
def solve(n, m, gs):
def union(u, v):
p, q = find(u), find(v)
if p == q: return
if rank[p] < rank[q]:... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
vector<int> par;
vector<int> sz;
vector<long long> w;
vector<vector<char> > a;
vector<vector<int> > lessy;
vector<vector<int> > more;
vector<int> color;
vector<bool> used;
bool globok = true;
int find_set(int v) {
if (par[v] == v)
return v;
else
return par[v] = ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
void fun() {}
int md = 1e9 + 7;
int __gcd(int a, int b) {
if (b == 0) return a;
return __gcd(b, a % b);
}
int poww(int a, int b, int md) {
if (b < 0) return 0;
if (a == 0) return 0;
int res = 1;
while (b) {
if (b & 1) {
res = (1ll * res * a) % md;
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 5;
const int MAX_M = 4e5 + 5;
const int INF = 0x3f3f3f3f;
struct Edge {
int v, next;
} es[MAX_N * MAX_N];
int n, m, fa[MAX_N << 1], cnt1, tot, head[MAX_N << 1], ind[MAX_N << 1],
eval[MAX_N << 1], cnt2;
char g[MAX_N][MAX_N];
queue<int> Q;
inline... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.util.*;
import java.io.*;
public class Main {
static FastScanner sc = new FastScanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder();
static ArrayList<ArrayList<Integer>> G;
static int[] indegree;
static int V,E;
s... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using std::max;
int head[2001], nxt[2000001], b[2000001], k, f[2001], comp[1001][1001], n, m,
nodes, d[2001], q[2001], t, h, ans[2001], orig;
int get() {
char ch = getchar();
while (ch != '<' && ch != '=' && ch != '>') ch = getchar();
return (ch == '<') ? (-1) : ((ch == '=') ? 0 : 1);... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.lang.invoke.MethodHandles;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Pri... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
vector<string> data;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
string row;
cin >> row;
data.push_back(row);
}
vector<vector<int> > set;
set.resize(2);
set[0].resize(n, 0);
set[1].resize(m, 0);
vector<vector<int> > se... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
public class CFD {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
private static long MOD = 1000L * 1000L * 1000L + 7;
private static final int[] dx = {0, -1, 0, 1};
private static final int[] dy = {1, 0, -1, 0};
private stati... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
public class Main {
private static int findSet(int x) {
if (x == set[x]) {
return x;
} else {
return se... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
try (PrintWriter out = new PrintWriter(System.out)) {
Solution solution = new Solution();
solution.in = new InputReader(getInput());
solu... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
vector<long long int> v[2005];
long long int vis[2005] = {0};
long long int in_stack[2005] = {0};
long long int value[2005];
bool dfs(long long int node) {
long long int i;
vis[node] = 1;
if (v[node].size() == 0) {
value[node] = 1;
return true;
}
in_stack[... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.*;
import java.util.*;
public class D {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Solver solver = new Solver();
solver.solve(in, out);
out.close();
}
private s... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 1005;
int n, m, fa[N], To[M * M], Ne[M * M], St[N], en, ind[N], wg[N];
char mp[M][M];
queue<int> q;
int Find(int u) { return fa[u] == 0 ? u : fa[u] = Find(fa[u]); }
void addedge(int u, int v) {
To[++en] = v, Ne[en] = St[u], St[u] = en;
++ind[v];
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = (((1 << 30) - 1) << 1) + 1;
const int nINF = 1 << 31;
void bad() {
cout << "No" << endl;
exit(0);
}
const int N = 2010;
int parent[N];
int sz[N];
int find(int x) { return parent[x] = (x ==... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | """Codeforces 1131D
"""
from sys import *
from typing import *
from collections import *
r, c = [int(i) for i in stdin.readline().strip().split(' ')]
a = [stdin.readline().strip() for i in range(r)]
def L(i: int) -> int:
return i
def R(i: int) -> int:
return r + i
parent = [0] * (r + c)
for i in range(r)... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 1005;
int n, m, res[2 * N], wyn[2 * N], p[2 * N], bla[2 * N];
char a[N][N];
vector<int> topo, child[2 * N], kto[2 * N];
bool vis[2 * N];
int Find(int x) {
if (x == p... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int MAX = 1002;
int n, m;
char table[MAX][MAX];
struct UnionFind {
int n, p[2 * MAX], w[2 * MAX];
UnionFind(int _n) {
n = _n;
for (int i = 0; i < n; i++) w[i] = 1;
for (int i = 0; i < n; i++) p[i] = i;
}
void uni(int i, int j) {
int u = root(i)... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3 + 5;
const long long MOD = 1e9 + 7;
int n, m, a[MAXN], vis[MAXN], pre[MAXN];
vector<int> v[MAXN];
char mp[MAXN][MAXN];
struct node {
int x, val;
} p;
queue<node> q;
int Find(int x) { return pre[x] == x ? x : pre[x] = Find(pre[x]); }
int main() {... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import sys,os,io
range = xrange
# INPUT
input_data = os.read(0,os.fstat(0).st_size)
input = io.BytesIO(input_data).readline
n,m = [int(x) for x in input().split()]
data = [input() for _ in range(n)]
rep = [-1]*(n+m)
for root in range(n+m):
if rep[root]>=0:continue
rep[root] = root
Q = [root]
while... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
class DisjointedSetMergingStructure {
vector<size_t> parent;
public:
explicit DisjointedSetMergingStructure(const size_t size) {
parent = vector<size_t>(size);
iota(parent.begin(), parent.end(), size_t());
}
void join(const size_t A, const size_t B) {
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class D541 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(), m = scanner.nextInt();
List<List<Integer>... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int> > equals_n_m(n + m, vector<int>());
vector<vector<int> > major_n_m(n + m, vector<int>());
vector<int> minor_n_m(n + m, 0);
vector<vector<char> > input_matrix(n, vector<char>(m));
vector<int> result(n + m... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
template <typename _tp>
inline void read(_tp& x) {
char c11 = getchar(), ob = 0;
x = 0;
while (c11 != '-' && !isdigit(c11)) c11 = getchar();
if (c11 == '-') ob = 1, c11 = getchar();
while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
if (ob) x = -x;
}
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n, m, father[maxn << 1], ru[maxn << 1], vis[maxn << 1], ans[maxn << 1];
vector<int> g[maxn << 1];
char s[maxn][maxn];
int findfather(int x) {
if (x == father[x]) return x;
int i = findfather(father[x]);
father[x] = i;
return i;
}
void u... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class GourmetChoice {
static int[] values = new int[2000];
static color[] state = new color[2000];
static DisjointSet dsu;
public static void main(String[]... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
void test() { cerr << "\n"; }
template <typename T, typename... Args>
void test(T x, Args... args) {
cerr << x << " ";
test(args...);
}
const int MAXN = (int)1e5 + 5;
const int MOD = (int)1e9 + 7;
char g[1005][1005];
int a[1005], b[1005];
int main() {
int n, m;
scan... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
template <size_t N>
struct DSU {
int parent[N];
void init(int n) { iota(parent + 1, parent + n + 1, 1); }
int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }
void merge(int x, int y) { parent[find(x)] = find(y); }
};
i... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const long long N = 2007;
long long n, m;
char a[N][N];
vector<long long> g[N], g1[N];
bool used[N];
long long c[N];
void dfs(long long u, long long cc) {
used[u] = 1;
c[u] = cc;
for (long long v : g[u]) {
if (!used[v]) dfs(v, cc);
}
}
long long ans[N];
void dfs... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
int n, m, fa[2005];
char s[2005][2005], G[2005][2005];
int in[2005], dis[2005];
int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; }
inline void join(int a, int b) {
int x = find(a), y = find(b);
if (x != y) fa[x] = y;
}
bool bfs() {
std::queue<int> q;
int i, u, cnt = 0;
for (i... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int N, M;
string grid[1000];
vector<vector<pair<int, char>>> startAdj;
vector<bool> visited;
vector<int> merged;
vector<vector<pair<int, char>>> adj;
vector<int> value;
vector<int> greaterCount;
void flood(int start, int pos) {
if (visited[pos]) return;
visited[pos] = t... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
vector<int> V[4444];
string s[4444];
int fa[4444], D[4444], ans[4444];
int fd(int x) {
if (x == fa[x]) return x;
return fa[x] = fd(fa[x]);
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
for (int i = 0; i < 4444; i++) fa[i] = i;
int n... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int p_mod = 998244353;
using namespace std;
long long fast_pow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return res % mod;
}
const int N = 2000 + 10;
char g[N][N];... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int MAXM = 200000;
inline void dfs(int);
struct edge {
int v, w;
};
int Error;
int dis[MAXN + 1];
bitset<MAXN + 1> vis, chk;
int sz[MAXN + 1];
vector<edge> to[MAXN + 1];
void dfs(int x) {
vis[x] = 1;
int si = sz[x];
for (int i = 0; i <... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Collection;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.UncheckedIOExcep... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int id[MAXN];
int cnt[MAXN];
vector<int> graph[MAXN];
int outDegree[MAXN];
int n, m;
char str[MAXN][MAXN];
bool vis[MAXN];
int value[MAXN];
int findRoot(int a) {
if (id[a] == a) {
return a;
}
return id[a] = findRoot(id[a]);
}
void unite(int ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1111;
struct Edge {
int to, next, val;
};
Edge edge[maxn * maxn];
int head[maxn << 1], vis[maxn << 1], dis[maxn << 1], cnt;
int fin[maxn << 1];
int n, m;
int f[maxn << 1];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void merge(int x, int... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | #include <bits/stdc++.h>
using namespace std;
int const N = 3e5 + 2, oo = 1e9;
long long const OO = 2e18;
double const eps = 1e-8, PI = acos(-1);
int mod = oo + 7;
string aa[1001];
int lar[2][1001], eq[2][1001], er[2][1001], val[2][1001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int now = 1;
int n, m;
... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | class mergefind:
def __init__(self,n):
self.parent = list(range(n))
self.size = [1]*n
self.num_sets = n
def find(self,a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.