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 MAXN = 2E5 + 10; int n; vector<pair<int, int> > E[MAXN]; vector<vector<int> > ans; void DFS(int u, int pre, int lastC) { int c = -1; for (int i = 0; i < E[u].size(); ++i) if (E[u][i].first != pre) { if (++c == lastC) ++c; if (ans.size() <= c) 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
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Bit...
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 double eps = 1e-9, pi = acos(-1.0); const long long inf = 2000000009; int n, a, b, p = 0, c; vector<pair<int, int> > v; vector<vector<int> > g, ans; vector<int> used; map<pair<int, int>, int> M; void dfs(int v, int p) { used[v] = 1; int c = 1, l; if (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
#include <bits/stdc++.h> using namespace std; struct r { int to, n; }; int max1 = 0; bool vis[300000] = {0}; vector<r> graph[200001]; vector<int> ans[200001]; void dfs(int v, int c) { if (vis[v]) return; vis[v] = 1; int p = 0; for (int i = 0; i < graph[v].size(); i++) { int to = graph[v][i].to; if (vi...
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; #pragma warning(disable : 4996) vector<pair<int, int>> X[200009]; int n, a, b, maxn; bool used[200009]; vector<int> ret[200009]; void dfs(int pos, int t) { if (used[pos] == true) return; used[pos] = true; int G = 1; for (pair<int, int> i : X[pos]) { if (used[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
n=input() e=[map(int,raw_input().split()) for i in range(n-1)] head=[-1] * 2 * n next=[0] * 2 * n for i in range(n-1): a,b=e[i] next[i]=head[a];head[a]=i; next[i+n]=head[b];head[b]=i+n; ans=[[] for i in range(n)] maxtime=0 q=[[0,0,0] for i in range(n)] qh,qe=0,1 q[0]=[1,0,0] while qh<qe: now,fa,t=q[qh] ...
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; const int MOD = 1000000007, INF = 1e9, MAX = 2e6; vector<long long int> v; vector<long long int> g[200005]; vector<long long int> ans[200005]; long long int marked[200005]; long long int global_size = 0; map<pair<long long int, long long int>, long long int> m; void dfs(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; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 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<pair<int, int>> e[200005]; vector<int> ans[200005]; int n, all; void dfs(int fa, int u, int k, bool selected) { int day = selected; for (auto i : e[u]) { int v = i.first, id = i.second; if (fa != v) { if (++day == k) { day++; } 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; int gn; array<int, 2> ge[200010]; vector<vector<int> > aj(200010); int vis[200010]; inline int ng(int vn, int ve) { if (ge[ve][0] == vn) return ge[ve][1]; else return ge[ve][0]; } vector<vector<int> > gm(200010); void dfs(int vn, int vp) { vis[vn] = 1; 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; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<pair<int, int> > > graph(n + 1); for (int e = 1; e < n; e++) { int u, v; cin >> u >> v; graph[u].emplace_back(v, e); graph[v].emplace_back(u, e); ...
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.*; import java.math.*; import java.text.*; public class Main { static PrintWriter out; static Reader in; public static void main(String[] args) throws IOException { input_output(); //out = new PrintWriter(System.out); //in = new Reader(new FileInpu...
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> const int MaxN = 2e5; using namespace std; vector<pair<int, int> > G[MaxN + 5]; vector<int> res[MaxN + 5]; int n, ans; void Dfs(int x, int fa, int t) { int day = 0; for (int i = 0; i < G[x].size(); i++) { int v = G[x][i].first, pos = G[x][i].second; if (v == fa) continue; 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
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long double pi = acos(-1.0); const string debug_line = "yolo"; const long double PI = acos((long double)-1.0); const long double eps = 1e-6; unsigned long long getRand() { return ((unsigned long long)rand() << 40) + ((unsigned lo...
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 T> void read(T &x) { x = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } template <typename 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> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; bool ispoweroftwo(long long n) { return n & (!(n & (n - 1))); } long long mod = 1000000007; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, -1, 0, 1}; bool test = 0; const long long inf = 1e18; const long...
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 dfs(long long p, vector<vector<long long> > &answ, vector<vector<pair<long long, long long> > > &g, long long cur, vector<long long> &not_use, vector<long long> &step) { for (long long i = 0; i < g[cur].size(); i++) { if (g[cur][i].first != 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
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("-Ofast") const int N = 1e5 + 5; const int mod = 1e9 + 7; vector<vector<pair<long long int, long long int> > > adj; vector<vector<long long int> > repair; long long int modexp(long long int a, long long int b, long long int mod) { long long int x = 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> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } using namespace std; vector<int> ans[(int)(5e5 + 500)]; vector<pair<int, 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 = 2 * 100 * 1000 + 2; int n, k; vector<pair<int, int>> adj[N]; vector<int> ans[N]; void dfs(int u, int par, int d) { for (int i = 0, cnt = 0; i < adj[u].size(); i++) { int v = adj[u][i].first, num = adj[u][i].second; if (v != par) { cnt += 1 + (c...
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 INF = 1000000000; const int MOD = 1000000007; const double EPS = 1e-9; vector<vector<pair<int, int>>> g; vector<int> donotwant; vector<vector<int>> ans; void dfs(int v, int p = -1) { int t = -1; for (auto i : g[v]) { if (i.first == p) continue; 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; vector<int> mpp[200010]; map<pair<int, int>, int> finde; map<int, vector<int>> ans; int vis[200010]; void dfs(int u, int color) { int cnt = 1; vis[u] = 1; for (auto v : mpp[u]) if (!vis[v]) { if (cnt == color) cnt++; ans[cnt].push_back(finde[{u, 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; const int N = 2e5 + 10; vector<int> graph[N]; struct Node { Node* parent; vector<Node*> children; int n; }; int n; map<pair<int, int>, int> numeral; int maxColor = 0; int maxDay = 0; vector<int> days[N]; pair<int, int> mpm(int a, int b) { return make_pair(min(a, b), m...
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 int getint() { int x = 0, f = 1, c = getchar(); for (; c < 48 || c > 57; f = c == '-' ? -1 : f, c = getchar()) ; for (; c > 47 && c < 58; x = x * 10 + c - 48, c = getchar()) ; return x * f; } const int N = 200005; int mx, ihead[N], cnt; struct E { 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; vector<pair<int, int> > sp[200000]; vector<int> days[200000]; int maxday = 0; void construct(int t, int d, int c) { int day = 0; for (int i = 0; i < sp[t].size(); i++) { if (sp[t][i].second != c) { day++; if (day == d) day++; days[day].push_back(sp...
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 + 5; int n; vector<pair<int, int> > v[N]; int a, b; vector<int> ans[N]; int mx; void dfs(int node, int parent, int time) { int cur = 0; for (auto it : v[node]) { int next = it.first; if (next != parent) { ++cur; cur += (cur == time)...
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[100010], dist[100010], col[110000], in[110000], out[110000], timer = 1; vector<long long int> gh[200010], ind[200010], ans[200010]; void dfs(long long int node, long long int p, long long int blocked) { long long int cnt = 0; for (long ...
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 sys import threading from collections import defaultdict def put(): return map(int, input().split()) def dfs(i, p, m): cnt = 1 z = 0 for j in tree[i]: if j==p: continue if cnt==m: cnt+=1 index = edge_index[(i,j)] ans[cnt].append(index) z = max(dfs(j,i,cnt...
PYTHON3
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 + 5; int n; vector<pair<int, int> > edge[maxn]; vector<int> a[maxn]; int res; void dfs(int u, int past, int day) { int now = 0; for (int i = 0; i < edge[u].size(); i++) { int v = edge[u][i].first; if (v == past) continue; int road = e...
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; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<pair<int, int> > > graph(n + 1); for (int e = 1; e < n; e++) { int u, v; cin >> u >> v; graph[u].emplace_back(v, e); graph[v].emplace_back(u, e); ...
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>> ev; unordered_map<int64_t, vector<uint64_t>> roads_by_day; visit[1] = true; int day = 0; for (auto e : ...
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 = 200200; vector<int> h[M], g[M], ans[M]; int n, m; bool used[M]; void read() { cin >> n; for (int i = 0; i < n - 1; ++i) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); h[x].push_back(i + 1); h[y].push_back(i + 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; 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; const int MAXN = 2e5 + 7; vector<pair<int, int> > adj[MAXN]; vector<int> ans[MAXN]; int mx = 1; void DFS(int v, int par = -1, int col = 0) { int lst = 1; for (auto p : adj[v]) { int u = p.first, id = p.second; if (u == par) { continue; } if (lst ==...
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<long long, long long> > g[200003]; vector<int> ans[200003]; bool f(pair<long long, long long> a, pair<long long, long long> b) { return ((long long)(g[a.first]).size()) < ((long long)(g[b.first]).size()); } int mx_day = -2; void dfs(int v, int p, int 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
#include <bits/stdc++.h> using namespace std; template <typename... Args> void dbg(Args... args) { ((cout << args << " "), ...); } const int INF = 1e9, N = 1e6; vector<pair<int, int>> g[N]; vector<int> ans[N]; bitset<N> used; int main() { int n; cin >> n; int maxi = 0; for (int i = 1; i < n; ++i) { int 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; constexpr int maxn = 2e5 + 5, inf = 0x3f3f3f3f; int n, m, cnt = 1; int head[maxn], col[maxn], du[maxn]; int k; struct edge { int u, v, nex; } e[maxn * 2]; vector<int> d[maxn]; inline void add(int u, int v) { e[++cnt].v = v; e[cnt].u = u; e[cnt].nex = head[u]; head...
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 size = 200005; int n, visit[size], tmax; vector<vector<int> > cnt, vertices; map<tuple<int, int>, int> roads; int dfs(int v, int p, int t) { tmax = max(t, tmax); visit[v] = 1; if (not cnt[t].size()) { if (roads.count(make_tuple(p, v))) cnt[t].push_...
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 C { class Edge{ int to; int ind; int day; public Edge(int to, int ind) { this.to = to; this.ind = ind; } } ArrayList<Edge>[] g; ArrayList<Edge> a=new Array...
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 MAX = 1e18; const long long MOD = 1e9 + 7; const double eps = 1e-8; long long t, m, n, k; vector<pair<int, int>> a[200005]; set<int> st; vector<pair<pair<int, int>, int>> p1, p2; vector<int> ans[200005]; void dfs(int u, int p, int color) { int last = 0; ...
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 INF = int(1e9); const long long INFll = 1ll * INF * INF; const long double ldINF = 1e+018; const long double EPS = 0.000000001; const int N = 100001; template <typename T> ostream& operator<<(ostream& out, pair<T, T>& a) { out << a.first << " " << a.second; re...
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; vector<pair<int, int> > g[maxn]; vector<int> solution[maxn]; int n; void dfs(int node, int p, int opentime) { int br = 1; for (auto i : g[node]) { if (i.first != p) { if (br == opentime) br++; solution[br].push_back(i.second); ...
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, i, j, a, b, mx, gag, son, parent[200005], mark[200005]; vector<pair<int, int> > g[200005]; vector<int> q[200005]; void build(int v) { for (int i = 0; i < g[v].size(); i++) { int to = g[v][i].first; if (to == parent[v]) continue; parent[to] = v; buil...
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; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void rset(); void init_test(); void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(20); init_test(); return 0; } template <typename T> void chmi...
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 = 2 * 1e5 + 10; vector<int> a[MAX], l[MAX]; int d[MAX]; map<pair<int, int>, int> mp; void dfs(int v, int c = 0, int p = 0) { int k = 0; for (auto u : a[v]) { if (u == p) continue; k++; if (k == c) k++; l[k].push_back(mp[{v, u}]); dfs(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
import java.io.*; import java.util.*; public class c2 { BufferedReader br; StringTokenizer in; PrintWriter out; public String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public int nextInt() throws IOE...
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> answer[300000]; bool used[300000]; vector<pair<int, int> > adj[300000]; int n; void dfs(int v = 1, int forb = -1) { used[v] = true; int step = 0; for (int i = 0; i < adj[v].size(); ++i) { int u, w; u = adj[v][i].first; w = adj[v][i].second; ...
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 = 200000; vector<pair<int, int> > g[N]; vector<int> days[N]; int ans; void dfs(int v, int p, int used) { int nxt = 1; for (int i = 0; i < g[v].size(); i++) { int u = g[v][i].first; int w = g[v][i].second; if (u != p) { if (nxt == used) nxt+...
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 INF = 1e9 + 5; long long int mod = 998244353; long long int nax = 2e5; vector<vector<long long int>> days(nax + 1); vector<vector<pair<long long int, long long int>>> g(nax + 1); void dfs(long long int node, long long int pa, long long int k, long lon...
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[300001]; vector<pair<int, int> > v[300001]; void dfs(int cur, int par, int prev_day) { int cur_day = 1; for (int i = 0; i < v[cur].size(); i++) { int x = v[cur][i].first; if (x == par) continue; if (cur_day == prev_day) cur_day++; ans[cur...
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 C { FastScanner in; PrintWriter out; class Edge { int x, num; public Edge(int x, int num) { this.x = x; this.num = num; } } List<Edge>[] edges; List<Integer>[] answer; int ans; void dfs...
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> > adj[200013]; vector<int> has[200013]; void dfs(int x, int p = 0, int use = 0) { int on = 0; for (auto i : adj[x]) if (i.first != p) { while (++on == use) ; has[on].push_back(i.second); dfs(i.first, x, on); ...
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 long long N = 2e5; const long long mod = 998244353; vector<vector<long long> > day(N + 1); vector<vector<pair<long long, long long> > > adj(N + 1); long long vis[N + 1], col[N + 1]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m...
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<pair<int, int> > > g; vector<vector<int> > arr; bool *used; void dfs(int v, int day) { used[v] = true; int d = 0; if (d == day) d++; for (int i = 0; i < (int)g[v].size(); i++) { if (used[g[v][i].first]) continue; arr[d].push_back(g[v][i].second...
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 Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(const Point& p) const { return Point(p.x + x, p.y + y); } Point operator-() const { return Point(-x, -y); } Point operator-(const Point& p) const { return *this + (-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
#include <bits/stdc++.h> using namespace std; struct edge { int to, next, id; } e[200010 << 1]; int box[200010], cnt; void init() { memset(box, -1, sizeof(box)); cnt = 0; } int ma; void add(int from, int to, int id) { e[cnt].id = id; e[cnt].to = to; e[cnt].next = box[from]; box[from] = cnt++; } vector<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 = 200005; int n; vector<pair<int, int> > v[N]; int a, b; vector<int> ans[N]; int mx = 0; void dfs(int node, int parent, int time) { int cur = 0; for (auto it = v[node].begin(); it != v[node].end(); ++it) { int next = (*it).first; if (next != parent) ...
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 MOD = 1e9 + 7; const int SIZE = 1e6 + 10; vector<pair<int, int> > e[SIZE]; int an[SIZE]; vector<int> res[SIZE]; void dfs(int x, int lt, int col) { set<int> use; use.insert(col); int now = 1; for (int i = 0; i < (((int)(e[x]).size())); ++i) { int y = e[...
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 = 200005; map<pair<int, int>, int> num; vector<int> G[MN], wyn[MN]; int dp[MN], used[MN]; int res; void dfs(int x) { int c = 0; used[x] = 1; int s = G[x].size(); for (int i = 0; i < s; ++i) { if (!used[G[x][i]]) { ++c; if (c == dp[x]) ++...
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
/** * Created by Anna on 26.03.2016. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.*; public class TaskC { StringTokenizer st; PrintWriter out; BufferedReader in; public st...
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 + 1000; vector<pair<int, int> > g[N]; vector<int> ans[N]; int n, sum, tot, u, v; void dfs(int x, int fa, int son_t) { int l = g[x].size(); int sum = 0; for (int i = 0; i < l; i++) { int v = g[x][i].first; if (v == fa) continue; sum++; ...
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 long long mod = 998244353; int n, rs = 0; vector<pair<int, int> > adj[200005]; vector<int> ans[200005]; void dfs(int nw, int pr, int dy) { int cnt = 0; for (auto i : adj[nw]) { int nx = i.first, nm = i.second; if (nx == pr) continue; cnt++; if (cnt...
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 <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cerr << endl; } const int INF = 1000 * 1000 * 1000 + 1000 * 1000;...
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<pair<int, int> > > g; vector<int> edge_color; void dfs(int cur, int forb) { int cur_color = 0; for (int i = 0; i < g[cur].size(); i++) { if (edge_color[g[cur][i].second] < 0) { if (cur_color == forb) { cur_color++; } edge_colo...
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 int max3(int a, int b, int c) { return max(a, max(b, c)); } inline int min3(int a, int b, int c) { return min(a, min(b, c)); } const int INF = 1e9; const long long LINF = 1e18; const double EPS = 1e-6; const double PI = acos(-1.0); const int maxn = 200020; int n; vec...
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> #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") const int N = 2e5 + 5; const long long int mod = 1e9 + 7; const long long int Mod = 998244353; const long double Pi = acos(-1); const long long int Inf = 4e18; using namespace std; vector<int> mark(N); vector<int> g[N], ans[...
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 dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int xChange[] = {0, 1, 0, -1}; int yChange[] = {1, 0, -1, 0}; const int N = 200005; int n, mx, cnt[N], d, ans; vector<int> adj[N]; map<pair<int, int>, int> mp; vector<vector<int>> vv(N); bool vi...
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.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Scanner; public class VKCupQualC { private static class pair { public int index, v, day = 0; public pair(int i, int v) { 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
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> adj[200005]; vector<vector<int>> edges; void dfs(int u, int p, int idx) { int i = 0; for (auto v : adj[u]) if (v.first != p) { if (i == idx) i++; if (i == edges.size()) edges.push_back(vector<int>()); edges[i].push_back(v.sec...
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 ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } vector<int> O[(200005)]; vector<pair<int, int> > g[(200005)]; int N, X, a, b; void dfs(int u, int p, int F) { int I = -1; for (auto &h : g[u]) if (h.first ^ p) { if (++I == F) ++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 + 1; const int INF = 1e9 + 7; const int inf = -1e9 - 7; const long double PI = 3.1415926535897932384626433832795; struct pt { int x, y, id; }; bool comp(pt a, pt b) { return a.x < b.x; } long long iyuza(pt a, pt b, pt c); long double yuza(pt a, pt 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 n; vector<long long int> adj[200015], ans[200015]; long long int mx = 0; map<pair<long long int, long long int>, long long int> ma; void dfs(long long int cur, long long int par, long long int not_allowed) { long long int c = 1; for (auto x : adj[cur]) { ...
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 inf = (int)2 * 1e9; vector<vector<pair<int, int> > > graph; vector<vector<int> > road; vector<set<int> > busy; void dfs(int x, int par) { int curr = 0; for (int i = 0; i < graph[x].size(); i++) if (graph[x][i].first != par) { while (busy[x].find(curr...
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 long long MAX = 1000000000000000000; long long mod = 1000000000; long double pi = 3.141592653589793238; void pls() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long N = 2e5 + 2; vector<pair<int, int>> g[N]; vector<int> res[N]; int mx; vo...
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 + 100; vector<pair<int, int> > E[MAXN]; vector<int> answer[MAXN]; int seen[MAXN]; set<int> added[MAXN]; void dfs(int u) { seen[u] = 1; int pointer = 1; for (pair<int, int> edge : E[u]) { int v = edge.first; int id = edge.second; if (se...
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.ArrayList; public class ProblemC { public static void main(String[] args) throws IOException { new ProblemC().run(); } public void run() throws IOException { MyInput sc = new MyInput(System.in); int n = sc.nextInt(); Graph g = new Graph(n)...
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<vector<int> > G; vector<vector<int> > ID; vector<vector<int> > ans; void addp(int id, int t) { while (ans.size() <= t) ans.push_back(vector<int>()); ans[t].push_back(id); } void solve(int from, int lab, int v) { int ctr = 0; for (int i = 0; i < G[v].si...
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; int n, all; int pre[2 * MaxN + 5], last[MaxN + 5], other[2 * MaxN + 5]; bool vis[MaxN + 5]; int ans[2 * MaxN + 5], num[2 * MaxN + 5], seq[2 * MaxN + 5], used[MaxN + 5]; vector<int> v[MaxN + 5]; void build(int x, int y, int k) { pre[++all] = last[x]; ...
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; int n, x; bool was[maxn]; vector<pair<int, int> > g[maxn]; vector<int> ans[maxn]; void dfs(int u, int c) { was[u] = true; int cur_c = 0; for (int i = 0; i < int(g[u].size()); i++) { int v = g[u][i].first; int id = g[u][i].second; 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 answ; vector<vector<pair<int, int> > > v; vector<vector<int> > q; vector<bool> used; void dfs(int vertex, int color) { used[vertex] = true; int c = 0; for (int i = 0; i < v[vertex].size(); i++) { if (!used[v[vertex][i].first]) { if (c == color) c++; ...
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 long long MN = 200111; long long deg[MN]; vector<long long> ke[MN]; vector<long long> ls[MN]; map<long long, long long> id[MN]; void dfs(long long u, long long fu, long long last) { long long c = 0; for (long long v : ke[u]) { if (v == fu) continue; ++c; ...
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Iterator; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.Writer; ...
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 N = 2e5 + 3; vector<vector<pair<long long, long long>>> v(N); vector<vector<long long>> day; void dfs(long long x, long long d, long long p) { long long temp = d; long long m = day.size(); for (pair<long long, long long> i : v[x]) { if (i.first != ...
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 = 200005; struct Edge { int id; int from, to; int day; Edge *prev; bool used; Edge(int id, int from, int to) : id(id), from(from), to(to) { used = false; } }; int n, m; vector<Edge> g[N]; Edge *q[N]; vector<int> res[N * 10]; int main() { int n; c...
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 C { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; public static void main(String[] args) throws IOException { try { in = new BufferedReader(new FileReader("quarth.in"));...
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; inline int nxt() { int first; scanf("%d", &first); return first; } vector<vector<int>> a; vector<char> used; vector<int> color; vector<int> p; void dfs(int v) { used[v] = 1; int i = 0; for (auto first : a[v]) { if (used[first]) continue; while (i == colo...
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> unsigned long int size = 0; struct point { unsigned int visited; std::vector<unsigned long int> neigbors; }; std::vector<point> graph; std::map<unsigned long int, std::vector<unsigned long int> > colors; std::map<std::pair<unsigned long int, unsigned long int>, unsigned long int> routes...
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 A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
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 l[200005], r[200005], sz; vector<int> g[200005], arr[200005]; void dfs(int v, int pr, int wt) { int cnt = 0; for (int i = 0, id, to; i < g[v].size(); ++i) { id = g[v][i]; if (v == l[id]) { to = r[id]; } else { to = l[id]; } if (to == ...
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> mat[200030]; map<pair<int, int>, int> mp; int main() { int n; cin >> n; vector<int> val(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; if (a > b) { swap(a, b); } pair<int, int> pq; pq.first ...
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 MX = 2e5 + 7; int n; vector<pair<int, int> > g[MX]; int id[MX]; vector<int> ans[MX]; int c[MX]; int sz; void solve(int v, int p = -1) { int d = 1; for (auto u : g[v]) { if (u.first == p) { continue; } while (c[v] == 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; long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } const int N = 2e5 + 10; vector<pair<int, int>> ad[N]; vector<int> ans[N]; int n; void dfs(int v, int l...
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.FileInputStream; // import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.copyOf; import s...
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 n, mx = 0; vector<long long> g[200001], used(200001), ans[200001]; map<pair<long long, long long>, long long> mp; void dfs(long long v, long long p, long long pr) { long long cnt = 0, c = 0, o = 0, q = 0; used[v] = 1; for (auto k : g[v]) { cnt++; c++...
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> template <typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); } template <typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); } const int maxn = 200 * 1000 + 5; int n; std::vector<std::pair<int, int>> e[maxn]; std::vector<int> v[maxn]; void go...
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.math.*; import java.io.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Hello { static ArrayList<Integer> a[] = new ArrayList[200005]; static ArrayList<Integer> e[] = new ArrayList[200005]; static ArrayList<Integer> ans[] = ...
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 = 2e5 + 5; vector<pair<int, int> > adj[N]; vector<int> plan[N]; int mxsz; void dfs(int nd, int pr, int fndn_day) { int day = 1; for (auto &&i : adj[nd]) { if (i.first == pr) continue; if (day == fndn_day) day++; mxsz = max(mxsz, day); plan[da...
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; vector<int> ans[200005]; vector<pair<int, int> > pms[200005]; int used[200005]; int MX = 0; void dfs(int cur, int denied) { used[cur] = 1; int cnt = 1; for (int i = 0; i < pms[cur].size(); ++i) { if (cnt == denied) cnt++; if (!used[pms[cur][i].first]) {...
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.List; import java.util.StringTokenizer; public class CF { static int[] excludeDay; static int[] nextFreeDay; static boolean[] isVisited; static ArrayList<Integer>[] schedule; sta...
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; struct aj { int ct; int r; aj(int a, int b) { ct = a; r = b; } }; vector<aj> adj[200005]; vector<int> day[200005]; int road[200005] = {0}, maxd = 0, n, i, a, b; void repai(int i, int rped) { int k = 0; for (vector<aj>::iterator it = adj[i].begin(); it !=...
CPP