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
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; const int MOD = 1e9 + 7; const int SZ = 2e5 + 100; vector<pair<int, int> > G[SZ]; vector<int> ans[SZ]; int nr[SZ]; void dfs(int v, int par) { int p = 0; for (auto& it : G[v]) { int u = it.first, id = it.second; if (u == par) continue; ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.io.*; import java.util.*; /* */ public class C { static FastReader sc=null; static int days[]; public static void main(String[] args) { sc=new FastReader(); PrintWriter out=new PrintWriter(System.out); int n=sc.nextInt(); Node nodes[]=new Node[n]; for(int i=0;i<n;i++)nodes[i]=new Node...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int> > > g(200100); bool used[200100]; int wayChet[200100]; int wayTime[200100]; vector<vector<int> > res(200100); void dfs(int j, int last) { used[j] = 1; int time = 1; if (last == 1) time = 2; if (last == 0) time = 1; for (int i = 0; i < ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, k, col[maxn]; vector<pair<int, int> > g[maxn]; vector<int> d[maxn]; void dfs(int v, int p) { int mx = 1; for (int i = 0; i < g[v].size(); i++) { if (g[v][i].first != p) { if (mx == col[v]) mx++; col[g[v][i].first] = mx; ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; vector<pair<int, int> > adj[N]; vector<int> ans[N]; void dfs(int u, int p, int idx) { int cnt = 0; for (auto it : adj[u]) if (it.first != p) { ++cnt; cnt += (cnt == idx); ans[cnt].push_back(it.second); dfs(it.first, u, ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; struct Valence { int index; int valence; bool operator<(Valence const &b) const { return valence < b.valence; } }; struct Edge { int from; int to; }; struct EdgeId { int edge; int id; bool operator<(EdgeId const &b) const { return edge < b.edge; } bool ope...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> ans[200005]; vector<pair<int, int> > g[200005]; int n, m, k, i, j, a[200005], b[200005], res; set<int> st; void dfs(int v, int p, int c) { int cur = 1; for (int j = 0; j < g[v].size(); j++) if (g[v][j].first != p) { if (cur == c) cur++; res =...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; bool used[1234567]; map<pair<int, int>, int> mapka; void dfs(int v, vector<vector<int> >& ans, int p = -1) { used[v] = 1; int cur = 0; for (int i = 0; i < g[v].size(); ++i) { int to = g[v][i]; if (!used[to]) { if (cur > p) { ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.io.*; import java.math.BigInteger; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.StringTokenizer; /** * Created by Leonti on 2016-03-20. */ public class C { public static void main(String[] args) { InputReader inputReader = new InputReader(System.in); Pr...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " = " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(na...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import os,sys n = int(raw_input()) nbs = [[] for i in xrange(n+1)] t=sys.stdin.read().split("\n") for i in range(n-1): l=t[i] u,v=map(int,l.split()) nbs[u].append((v,i+1)) nbs[v].append((u,i+1)) left,right = 0,1 ans = [[] for i in xrange(n+1)] total = 0 stateL = [[1,1,0] for i in xrange(1,n+1)] while le...
PYTHON
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> g[200007]; bool visited[200007]; int reservedDay[200007]; int res[200007]; vector<int> printRes[200007]; int maxDay = 0; void visit(int u) { visited[u] = true; int avDay = 1; for (int i = 0; i < g[u].size(); i++) { if (!visited[g[u][i].secon...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; void bfs(vector<vector<uint64_t>>& v, map<tuple<uint64_t, uint64_t>, uint64_t>& road_nr) { uint64_t len = v.size(); vector<bool> visited(len, false); visited[0] = true; visited[1] = true; deque<tuple<uint64_t, uint64_t>> p; map<uint64_t, vector<uint64_t...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 2 * 200000; const int MAXM = MAXN - 1; int n; int deg[MAXN]; int ghead[MAXN], gprv[2 * MAXM], gnxt[2 * MAXM], gto[2 * MAXM]; int ihead[MAXN], iprv[2 * MAXM], inxt[2 * MAXM]; int ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<int, int>> g[n + 1]; for (int i = 1; i <= n - 1; ++i) { int u, v; cin >> u >> v; g[u].emplace_back(v, i); g[v].emplace_back(u, i); } int sum = 0; vector<vect...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; int mn = 1; vector<vector<pair<int, int>>> G; vector<vector<int>> day; vector<int> used; void DFS(int n, int cl) { int cc = 1; for (int i = 0; i < G[n].size(); i++) { if (cl == cc) { cc++; } if (!used[G[n][i].first]) { day[cc - 1].push_back(G[n][...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; long long n; vector<pair<long long, long long> > g[200005]; long long sz; vector<long long> ans[200005]; void dfs(long long s, long long pr, long long tt) { long long cur = 0; for (auto i : g[s]) { if (i.first == pr) continue; cur++; if (cur == tt) cur += 1;...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<long long> v[200001]; long long ans = 0; vector<long long> m[200001]; map<pair<long long, long long>, long long> edges; void dfs(long long x, long long p, long long w) { long long d = 1; for (long long i = 0; i < (long long)v[x].size(); i++) { if (v[x][i] == ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MM = 2e5 + 127; vector<pair<int, int> > edge[MM]; int degree[MM]; vector<int> ans[MM]; int maxT; void dfs(int cur, int par, int when) { int timer = 0; for (auto u : edge[cur]) { if (u.first != par) { if (timer == when) { timer++; } ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200100, mod = 1e9 + 7, maxa = 1e6 + 100, maxb = 23; const long long inf = 2e18 + 13; long long max(long long x, long long y) { return (x > y ? x : y); } long long min(long long x, long long y) { return (x < y ? x : y); } vector<pair<int, int> > e; vector<in...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> const double pi = 3.14159265359; const int MOD = 1000000007; const int dr[4] = {-1, 1, 0, 0}; const int dc[4] = {0, 0, -1, 1}; double sinA(double dig) { return sin(dig * pi / 180); } double cosA(double dig) { return cos(dig * pi / 180); } double tanA(double dig) { int we = dig; if (we == di...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; struct Edge { int to; int index; int color; size_t inv_pos; Edge(int to = -1, int index = 0, size_t inv_pos = 0) : to(to), index(index), color(-1), inv_pos(inv_pos) {} }; int n; vector<vector<Edge>> g; void bfs(int start) { queue<pair<int, int>> q; q.pus...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MN = 2e5 + 44; vector<pair<int, int> > graph[MN]; vector<int> ans[MN]; void dfs(int x, int y = -1, int color = -1) { int last = 0; for (auto v : graph[x]) if (v.first != y) { if (last == color) last++; ans[last].push_back(v.second); dfs(v...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> gr[200500], v[200500]; map<pair<int, int>, int> mp; int c[200500]; void dfs(int v, int par, int last) { int col = 1; if (last == col) col++; for (int x : gr[v]) { if (x == par) continue; c[mp[make_pair(v, x)]] = col; dfs(x, v, col); col++; ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; public final class C { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); static ArrayList<ArrayList<edge>> g; static long mod=(long)...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> adj[200004], ans[200004]; int clr[200004], mx = 0; map<int, map<int, int> > mp; void bfs(int src) { int u, v, p, q, r, sz; queue<int> qu; qu.push(src); while (!qu.empty()) { u = qu.front(); qu.pop(); sz = adj[u].size(); p = 0; for (in...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int nmax = 300010; int n; vector<pair<int, int> > g[nmax]; int u[nmax]; int color[nmax], cnt[nmax]; vector<int> ans[nmax]; void dfs(int v, int p = -1, int come = 0) { int ptr = 1; for (int i = 0; i < g[v].size(); i++) { int num = g[v][i].second, to = g[v][i].f...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MaxN = 2e5, MaxM = 4e5; int n, all; int pre[MaxM + 5], last[MaxN + 5], other[MaxM + 5]; bool vis[MaxN + 5]; int ans[MaxM + 5], num[MaxM + 5], used[MaxN + 5]; int seq[MaxM + 5]; vector<int> v[MaxN + 5]; void Build(int x, int y, int d) { pre[++all] = last[x]; la...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; int cunt[200000 + 342]; bool printed[200000 + 342]; vector<pair<int, int> > adj[200000 + 342]; int pussy[200000 + 342]; vector<int> bc[200000 + 342]; void solve(int cur, int par, int t) { int now = 0; for (int i = 0; i < adj[cur].size(); i++) { int nxt = adj[cur][i]...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; int read() { int ans = 0, f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); } return ans * f; } const int N = 2e5 + 5; int n, d...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int INF = 0x3f3f3f3f; int n, du[MAXN]; struct Edge { int to, next; } G[MAXN << 1]; int sz, head[MAXN]; void add(int u, int v) { G[sz] = {v, head[u]}; head[u] = sz++; } vector<int> ret[MAXN]; void dfs(int u, int fa, int last) { int now...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const long long LLINF = (long long)1e18; int n; vector<pair<int, int> > g[N]; vector<int> roads[N]; void dfs(int v, int p = -1, int id = -1) { int pos = -1; for (auto t : g[v]) { int...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int max_n = 2e5 + 100; struct edge { int to, num, color, rev, next; } E[max_n << 1]; int head[max_n]; int cnt = 1; void add(int from, int to, int num, int rev, int color = 0) { E[cnt].to = to; E[cnt].next = head[from]; E[cnt].num = num; E[cnt].color = color;...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long min(long long a, long long b) { return (a < b) ? a : b; } long long max(long long a, long long b) { return (a > b) ? a : b; } long long fp(long long a, long long b) { if (b == 0) return 1; long long x = fp(a, b / 2); x = (x * x) % mo...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<long long> vis(200010); vector<long long> adj[200010]; vector<long long> res[200010]; map<pair<long long, long long>, long long> M; long long n, groups = 0; void dfs(long long node, long long col) { vis[node] = 1; for (int i = 0; i < adj[node].size(); i++) { ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; vector<pair<int, int> > g[MAXN]; int n; bool read() { if (scanf("%d", &n) < 1) { return false; } for (int i = 0; i < (int)n; ++i) { g[i].clear(); } for (int i = 0; i < (int)n - 1; ++i) { int a, b; scanf("%d%d", &a, &b); ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; long long int node, edge, vis[200010], dist[200010], col[200010], in[200010], out[200010], timer = 1; vector<long long int> gh[200010], ind[200010], ans[200010]; void dfs(long long int current, long long int blocked) { long long int cnt = 0; vis[current] = 1; for ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; struct Edge { size_t to, id; Edge(size_t t = 0, size_t i = 0) : to(t), id(i) {} }; vector<Edge> edges[200005]; vector<size_t> ans[200005]; void dfs(size_t v, size_t p = -1, size_t day = -1) { size_t currDay = 0; if (currDay == day) ++currDay; for (size_t i = 0; i ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int M = 200005; const int mod = 1e9 + 7; map<int, int> id[M]; vector<int> adj[M], ans[M]; int n, mans; void dfs(int node, int p, int l) { mans = max(mans, (int)adj[node].size()); int turn = 1; for (auto i : adj[node]) { if (i == p) continue; if (turn == ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adjList[200010]; vector<int> day[200010]; void dfs(int u, int p, int sk) { int currd = 0; for (auto x : adjList[u]) { int v = x.first; if (v == p) continue; if (currd == sk) currd += 1; day[currd].push_back(x.second); dfs(v, u...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int mn = 200010; int n, k; vector<int> ans[mn]; vector<pair<int, int> > e[mn]; int clr[mn]; void dfs(int v, int p, int cl) { int q = 1; for (int i = 0; i < e[v].size(); i++) { if (e[v][i].first == p) { continue; } if (q == cl) { q++; } ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.util.*; import java.io.*; public class TaskC { private FastScanner in; private PrintWriter out; private class Edge { int from; int to; int index; public Edge(int from, int to, int index) { this.from = from; this.to = to; this...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; public class C { static ArrayList<Integer>[][] way; static ArrayList<ArrayList<Integer>> answer; static PrintWriter out; public static void main(String[]...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200000; std::vector<int> ans[N]; std::vector<std::pair<int, int> > edge[N]; int maxi = 0; void dfs(int u, int par, int day) { int cnt = 0; for (int i = 0; i < edge[u].size(); i++) { std::pair<int, int> v = edge[u][i]; if (v.first == par) continue; ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<int>; using VC = vector<char>; using VS = vector<string>; using VL = vector<long long>; using VVI = vector<VI>; using VVL = vector<VL>; using MII = map<int, int>; using MIVI = map<int, VI>; using MSS = map<string, string>; using MLL =...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200123; vector<pair<int, int> > nbs[N]; int deg[N]; int act[N]; int taken[N]; int par[N]; int paredge[N]; int asparent[N]; int h[N]; int n, a, b; void dfs(int v, int p = -1, int e = -1, int ch = 0) { par[v] = p; paredge[v] = e; h[v] = ch; for (pair<int...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 1; struct v { int i, c; }; int n, a, b; map<int, map<int, int>> tr; int que[N], l, r; stack<int> st; int bV[N] = {0}; v V[N] = {0}; bool d[N] = {0}; deque<deque<int>> de; void rec(int i = V[0].i, int c = 1) { for (map<int, int>::iterator it = tr...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> ans[200001]; vector<pair<int, int> > v[200001]; int vis[200001]; void dfs(int s, int r) { int d = 0; vis[s] = 1; for (auto i : v[s]) { if (vis[i.first] == 0) { int a = i.first; int b = i.second; d++; if (r == d) { d++; ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf("%d", &x); return x; } inline string getStr() { char ch[1000000]; scanf("%s", ch); return ch; } inline string getStr2() { char ch[5]; scanf("%s", ch); return ch; }; template <class P, class Q> inline P smin(P &a, Q ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n, result = 0, lab[MAXN]; vector<pair<int, int> > adj_list[MAXN]; vector<vector<int> > ans; void dfs(int u, int last, int skip) { int curr; if (skip != 1) curr = 1; else curr = 2; for (int i = 0; i < adj_list[u].size(); i++) { ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { ArrayList<Integer>[] g; ArrayList<Integer>[] id; ArrayList<Integer>[] at; boolean[] was; int[] par; int[] parColor; public void solve(int testNumber, FastScanner in, PrintWriter out) { int n = i...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> e[200005]; vector<int> ans[200005]; int n, all; void dfs(int fa, int u, int k) { int day = 0; for (auto i : e[u]) { int v = i.first, id = i.second; if (fa != v) { if (++day == k) { day++; } all = max(all, day); ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import javafx.geometry.Pos; import javafx.util.Pair; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.security.cert.PolicyNode; import java.util.*; public class Solution { BufferedReader in; PrintWriter out; StringTokenizer st; String nextToken() throws IOExc...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; long long gcd1(long long a, long long b) { if (a == 0) return b; return gcd1(b % a, a); } long long modx(long long base, long long ex) { long long ans = 1LL, val = base; while (ex > 0LL) { if (ex & 1LL) ans = (ans * val) % 1000000009LL; val = (val * val) % 1...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000 + 42; struct { int u, v; int to(int from) const { return u + v - from; } } edges[MAXN]; list<int> graph[MAXN]; list<int> roads[MAXN]; bool used[MAXN] = {}; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; ++i) { scanf("%d%d",...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * Created by roman on 21.03.2016. */ public class Task3 { public BufferedReader bufferedReader; public StringTokenizer stringTokenizer; public PrintWriter print...
JAVA
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > g[200000]; int col[200000]; vector<int> plan[200000]; void dfs(int v, int p, int bad) { int cur = 0; for (pair<int, int> to : g[v]) if (to.first != p) { if (cur == bad) ++cur; col[to.second] = cur; dfs(to.first, v, cu...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; typedef struct { int sum, suf, pre, max; } Node; int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; } const int MAXN = 2e5 + 100; const int UP = 31; const long long int highest = 1e18; const double pi = acos(-1); const double Phi = ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; void bfs(vector<vector<uint64_t>>& g, map<tuple<uint64_t, uint64_t>, uint64_t>& i2r) { vector<bool> visit(g.size()); deque<tuple<uint64_t, uint64_t, uint64_t>> ev; unordered_map<int64_t, vector<uint64_t>> roads_by_day; visit[1] = true; int day = 0; for ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> v[222222]; map<pair<int, int>, int> m; bool vis[222222]; const long long INF = 1000000000; vector<int> ans[222222]; int ans1 = 1; void dfs(int k, int last) { int num = 0; for (int i = 0; i < v[k].size(); ++i) if (!vis[v[k][i]]) { if (num == last) n...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; int N, maxd; vector<pair<int, int> > adj[200005]; vector<int> days[200005]; bool seen[200005]; void dostuff(int n, int d) { seen[n] = true; int i = 1; for (auto a : adj[n]) { if (!seen[a.first]) { if (i == d) { i++; } days[i].push_back(a....
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int mxn = (2e5) + 5; vector<pair<int, int> > tr[mxn]; vector<int> ans[mxn]; int mx; void dfs(int v, int p, int in) { mx = max(mx, in + 1); int c = -1; for (int i = 0; i < tr[v].size(); ++i) { int u = tr[v][i].first; int x = tr[v][i].second; if (u == ...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; const int md = 1e9 + 7; const int INF = 1e9 + 7; const double EPS = 1e-10; int n; const int MAXN = 200010; map<pair<int, int>, int> edge; vector<int> g[MAXN]; bool vis[MAXN]; int cant[MAXN]; vector<int> first_not_used(MAXN, 1); vector<int> day[MAXN]; int ans; void dfs(int v...
CPP
638_C. Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
2
9
#include <bits/stdc++.h> using namespace std; class graphal { public: int n, mx = 0; vector<pair<int, int> > *ed; vector<int> *ans; graphal(int n) { this->n = n; ed = new vector<pair<int, int> >[n]; ans = new vector<int>[n + 1](); } ~graphal() { delete[] ed; delete[] ans; } void add...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 10010; long long t2[N], t3[N]; void solve() { string s; cin >> s; int n = s.size(); s += "#####"; long long res = 0; set<string> suffs; t2[n - 2] = 1; t3[n - 3] = 1; for (int i = n - 1; i >= 5; --i) { if (i + 3 < n) { if (s.substr(i...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; while (a >= 1000000007) a -= 1000000007; } int pow(int a, int b) { in...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; long long int a[1000005][5] = {0}; map<string, long long int> mp, tot; void fn(long long int l, long long int r); string str; int main() { cin >> str; fn(0, str.length() - 1); cout << tot.size() << endl; for (auto t : tot) cout << t.first << endl; return 0; } void...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; char s[100111]; int n; int F[100111][2]; int sz[2] = {2, 3}; int Can(int k, int tp) { if (F[k][tp] != -1) return F[k][tp]; if (k + sz[tp] - 1 == n) return 1; if (k + sz[tp] - 1 > n) return 0; F[k][tp] = 0; if (tp == 0) { if (s[k] == s[k + 2] && s[k + 1] == s[k...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int len = s.length(); bool dp[len + 2][2]; memset(dp, false, sizeof(dp)); dp[len][0] = dp[len][1] = true; set<string> ans; for (int i = len - 2; i > 4; --i) { if ((dp[i + 2][0] && s.substr(i, 2) != s.substr(i + 2, 2)) || ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.*; import java.lang.reflect.Array; import java.math.*; import java.util.*; public class icpc { static String s = ""; static HashSet<String> h = new HashSet<>(); static HashSet<Integer> h1 = new HashSet<>(); public static void main(String[] args) throws IOException { // Reader ...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; set<string> vals; int N; vector<bool> seen; map<pair<pair<int, int>, int>, bool> rem; bool cansplit(int current, int prevl, int length) { pair<pair<int, int>, int> key = make_pair(make_pair(current, prevl), length); map<pair<pair<int, int>, int>, bool>::iterat...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; bool valid[10000 + 100]; set<string> ans; int main() { string s; getline(cin, s); valid[s.length()] = 1; for (int i = s.length() - 1; i > 4; --i) { if (valid[i + 2]) { string t = s.substr(i, 2); if (s.find(t, i + 2) != i + 2 || valid[i + 5]) { ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { if (y == 0) return 1ll; if (y % 2) return (x % 1000000007 * power(x, y - 1) % 1000000007) % 1000000007; else return power((x * x) % 1000000007, y / 2) % 1000000007; } set<string> ans; int main() { ios_base::sync_wi...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; char S[maxn]; set<string> ans; bool f[maxn][3]; int main() { scanf("%s", S); int len = strlen(S); f[len - 2][0] = true; f[len - 3][1] = true; for (int i = len - 2; i >= 5; --i) { if (f[i + 2][0] && (S[i] != S[i + 2] || S[i + 1] != S[i ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
/** * Created by yume on 2016/5/25. */ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeSet; public class Main { public static void main(final String[] args...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int MM = 1e4 + 5; int n; bool dp[MM][2]; string s; int main() { cin.tie(0)->sync_with_stdio(0); cin >> s; n = s.size(); if (n == 5) return cout << "0\n", 0; set<string> ss; dp[n - 2][0] = dp[n - 3][1] = 1; for (int i = n - 4; i > 4; i--) { string two...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int n; bool dp[10001][2]; string str; set<string> s; int main() { cin >> str; n = str.length(); for (register int i = n - 2; i >= 5; --i) { if (i + 2 == n) dp[i][0] = 1; if (i + 3 == n) dp[i][1] = 1; if (dp[i + 3][0]) dp[i][1] = 1; if (dp[i + 2][1]) dp...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.util.Scanner; import java.util.TreeSet; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); TreeSet<String> suffixes = new TreeSet<>(); String word = sc.nextLine(); sc.close(); String tempSubstring; boolean...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java....
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#!/usr/bin/python2 # -*- coding: utf-8 -*- import sys import os def build_must(s): s = "".join(reversed(s)) r = [None, None, s[:2], s[:3]] c3 = s[:3] c2 = s[1:3] for c in s[3:]: c3 = c3[-2] + c3[-1] + c c2 = c2[-1] + c t2 = t3 = None if r[-3] is not None: ...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-9; set<string> seen[10009], ret; string s; int n; void dfs(int ind, string next) { if (!seen[ind].insert(next).second) return; if (ind - 2 > 4) { string x = ""; x += s[ind - 2]; ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const double eps = 0.000000000000001; string convertstring(long long n) { stringstream ss; ss << n; return ss.str(); } int len, dp[10005][4]; string s; int solve(int ind, int last) { if (ind == len) return dp[ind][last] = 1; int &ans = dp[ind][last]; if (ans != ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; set<string> tmp; bool dp[10010][5]; void go(int i, int prv) { if (dp[i][prv]) return; dp[i][prv] = 1; if (s.substr(i, 2) != s.substr(i - prv, prv) && i + 6 < s.size()) { string t = s.substr(i, 2); reverse(t.begin(), t.end()); tmp.insert(t); g...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; unordered_set<string> suffixes; bool checked[2][10001]; void solve(int end, const string& prev) { bool& c = checked[prev.length() - 2][end]; if (c) return; c = true; for (int i = 2; i < 4; ++i) { if (end - i < 5) continue; string suffix = s.substr(...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
from sys import * setrecursionlimit(200000) d = {} t = set() s = input() + ' ' def gen(l, ll): if (l, ll) in t: return t.add((l, ll)) if l > 6: d[s[l - 2 : l]] = 1 if s[l - 2 : l] != s[l : ll]: gen(l - 2, l) if l > 7: d[s[l - 3 : l]] = 1 if s[l - 3 : l] != s[l : ll]: gen(...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; public class Main { private static StringTokenizer st; private static BufferedReader br; public static long MOD = 1000000007; public ...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); int fh = 1; while (ch < '0' || ch > '9') { if (ch == '-') fh = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= fh; } template <typename...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } int power(int a, int b, int m, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % m) if (b & 1)...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int dp[2][10005]; char s[10005]; int main() { cin >> s; int n = strlen(s); dp[0][n - 2] = 1; dp[1][n - 3] = 1; for (int i = n - 4; i >= 0; i--) { if (dp[1][i + 2] == 1 || (dp[0][i + 2] == 1 && (s[i] != s[i + 2] || s[i + 1] != s[i + 3]))) dp[0][i]...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; using lli = long long int; using llu = long long unsigned; using pii = tuple<lli, lli>; using piii = tuple<lli, lli, lli>; using piiii = tuple<lli, lli, lli, lli>; using vi = vector<lli>; using vii = vector<pii>; using viii = vector<piii>; using ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int n; string s; set<string> a; int dp[10010][2]; bool ok(int i, int x) { if (i + x > n) return 0; if (i + x == n) return 1; if (i + x == n - 1) return 0; if (dp[i][x - 2] != -1) return dp[i][x - 2]; int &ref = dp[i][x - 2]; if (ok(i + x, 5 - x)) ref = 1; ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.util.*; import java.io.*; public class a { public static int[][] memo; public static String s; public static void main(String[] args){ Scanner br = new Scanner(System.in); s = br.next(); memo = new int[4][s.length()]; for(int i = 0;i<4;i++){ Arrays.fill(memo[i], -1); } TreeSet<String> suff...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; public class MO { public static void main(String[] args) throws NumberFormatException, IOException { Scanner in = new Scanner(...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import sys sys.setrecursionlimit(10000) s = input() s = s[5:] + " " res = set() aux = set() def getWords(x,y): if (x,y) in aux: return aux.add((x,y)) if x > 1 and s[x:y] != s[x-2:x]: res.add(s[x-2:x]) getWords(x-2,x) if x > 2 and s[x:y] != s[x-3:x]: res.add(s[x-3:x]) ...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = raw_input().strip() l = len(s) a = [[] for i in xrange(l + 2)] a[l-1] = a[l+1] = None for i in xrange(l - 2, 4, -1): t = s[i:i+2] if a[i+2] is not None and a[i+2] != [t]: a[i].append(t) t = s[i:i+3] if a[i+3] is not None and a[i+3] != [t]: a[i].append(t) if not a[i]: a[i]...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; int dp[N][4]; set<string> st[26]; set<string>::iterator it; string s; int n; void solve(int idx, int last) { if (idx <= 5) { return; } if (last != 0 && dp[idx][last - idx] != 0) { return; } string t, u; t.push_back(s[idx]); t.pus...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <typename Tp> inline void read(Tp &x) { static char c; static bool neg; x = 0, c = getchar(), neg = false; for (; !isdigit(c); c = getchar()) { if (c == '-') { neg = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; ...
CPP