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;
vector<long long> day;
void dfs(long long src, vector<vector<pair<long long, long long>>> &adj,
vector<bool> &vis, long long dont = -1, long long par = -1) {
vis[src] = true;
long long cur = 1;
for (auto &x : adj[src]) {
long long dest = x.first, roadInde... | 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 = 1e9 + 7;
long long dx[] = {-1, 0, 1, 0};
long long dy[] = {0, -1, 0, 1};
vector<pair<long long, long long> > g[200005];
vector<long long> ans[200005];
long long res;
void dfs(long long x, long long p, long long t) {
long long cnt = 0;
for (auto 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 N = 200200;
vector<int> d[N];
vector<pair<int, int>> g[N];
int n, k;
void go(int cur, int u = -1, int par = -1) {
int day = 0;
for (auto it : g[cur])
if (it.first != par) {
if (day == u) ++day;
d[day].push_back(it.second);
if (day > k) k ... | 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 MODD = 1000000007LL;
long long poww(long long x, long long y, long long MODD) {
if (x == 0LL && y == 0LL) {
return 1LL;
}
long long ret = 1;
while (y) {
if (y & 1LL) {
ret *= x;
ret %= MODD;
}
x *= x;
x %= MODD;
y ... | 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;
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 | #include <bits/stdc++.h>
using namespace std;
const int N = 212345;
vector<pair<int, int> > v[N];
bool used[N];
set<int> st[N];
vector<int> ans[N];
int tt = 0;
void dfs(int x) {
used[x] = 1;
int cnt = 1;
for (int i = 0; i < v[x].size(); i++) {
int to = v[x][i].first;
int ti = v[x][i].second;
if (!used... | 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 par {
int ver, id;
par(){};
par(int _ver, int _id) : ver(_ver), id(_id){};
};
int i, j, n, m, maxi, x, y, id, b[300000];
vector<par> a[300000];
vector<int> ans[300000];
void DFS(int x, int k) {
b[x] = 1;
int cnt = 0;
for (int i = 0; i < (int)a[x].size(); ... | 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 comment(linker, "/STACK:66777216")
using namespace std;
long long n, m, t, l, r, x, y;
vector<long long> a[200005];
bool vis[200005];
bool maked[200005];
vector<long long> ans[200005];
map<pair<long long, long long>, long long> ind;
int main() {
cin >> n;
for (int i = 0; i < n - 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;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second != b.second) return a.second > b.second;
return a.first < b.first;
};
class graphal {
public:
int n, mx = 0;
vector<pair<int, int> > *ed;
vector<int> *ans;
int *taken;
graphal(int 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;
const int N = 200000 + 10;
struct node {
vector<int> children;
vector<int> road;
int color;
int parentDay;
};
node lst[N];
int main() {
int n, i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
lst[i].color = lst[i].parentDay = 0;
}
int ans = 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;
struct Node {
vector<int> neib;
vector<int> ednum;
bool done;
};
Node* nodes;
vector<int>* days;
void dfs(int nodeNum, int parentDay) {
int day = 0;
nodes[nodeNum].done = true;
for (int i = 0; i < (int)nodes[nodeNum].neib.size(); i++) {
if (day == parentDay)... | 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 {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static class Edge {
int to, id;
public Edge(int to, int id) {
this.to = to;
this.id = id;
}
}
List<Edge>[] g;
int[] col;
void dfs(int v, int p, int forbColor) {
int ... | 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 MAXN = 2e5 + 10;
const int INF = 1e9 + 7;
bool used[MAXN];
vector<pair<int, int>> G[MAXN];
vector<int> roads[MAXN];
int dfs(int v, int day) {
used[v] = 1;
int ans = G[v].size();
int firstday = day;
int toadd = -1;
for (int i = 0; i < G[v].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>
#pragma comment(linker, "/STACK:128777216")
using namespace std;
const long long LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
void prepare(string s) {
if (s.length() != 0) {
freopen((s + ... | 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 string nameFiles = "";
void error(vector<string>::iterator) {}
template <typename T, typename... Args>
void error(vector<string>::iterator cur_var, T a, Args... args) {
cerr << cur_var->substr((*cur_var)[0] == ' ') << " = " << a << endl;
error(++cur_var, args...);... | 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> adj[200009], num[200009], solution[200009];
int degree[200009];
void dfs(int u, int p, int upcolor) {
vector<int> v;
int timer = 0;
for (int i = 0; i < adj[u].size(); i++)
if (adj[u][i] != p) {
timer++;
if (timer == upcolor) {
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;
vector<int> day;
void dfs(int src, vector<vector<pair<int, int>>> &adj, vector<bool> &vis,
int dont = -1, int par = -1) {
vis[src] = true;
int cur = 1;
for (auto &x : adj[src]) {
int dest = x.first, roadIndex = x.second;
if (dest == 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;
int x;
vector<int> g[200010];
map<pair<int, int>, int> ans;
map<pair<int, int>, int> pos;
bool cmp(int x, int y) {
if (g[x] >= g[y]) return false;
return true;
}
vector<vector<int> > res;
bool u[200010];
int main() {
cin >> x;
for (int i = 0; i < x - 1; i++) {
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>> adj[300001];
vector<int> parent(200001);
int cma = 0;
vector<int> make[200001];
vector<bool> visited(200001);
void dfs(int v, int p = -1) {
visited[v] = 1;
int cid = 0;
for (auto it : adj[v]) {
if (!visited[it.first]) {
if (cid == p) 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 N = (int)3e5;
int n;
vector<int> g[N];
vector<int> day[N];
struct edge {
int a, b;
} E[N];
void dfs(int v, int e, int bad) {
int curDay = 0;
for (int id : g[v]) {
if (id == e) continue;
if (++curDay == bad) curDay++;
day[curDay].push_back(id);
... | 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>
int N, head[200001], next[399999], to[399999], id[399999], E, O, q[200001],
fa[200001], d[200001];
std::vector<int> V[200001];
int main() {
scanf("%d", &N);
for (int i = 1, u, v; i < N; i++) {
scanf("%d%d", &u, &v);
d[u]++;
d[v]++;
next[++E] = head[u], to[E] = v, id[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;
typedef struct lnod {
int nod, nr;
lnod *next;
} * nod;
int i, n, x, y, timer[200005], nr[200005], ans;
nod lda[200005], rs[200005];
void add(int x, int z, nod &y) {
nod p = new lnod;
p->nod = x;
p->nr = z;
p->next = y;
y = p;
}
void dfs(int x, int tata) {
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 N = 1e6 + 10;
int du[N];
vector<int> g[N];
struct Edge {
int from, to, nex;
} edge[N];
int h[N], idx, ans;
void add(int u, int v) {
Edge E = {u, v, h[u]};
edge[idx] = E;
h[u] = idx++;
}
int n;
void dfs(int u, int fa, int last) {
int j = 1;
for (int 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 traverse(int index, int parent_index, int parent_color,
vector<vector<int> > &G_to, vector<vector<int> > &G_idx,
vector<vector<int> > &ans) {
int c = 0;
for (int j = 0; j < G_to[index].size(); j++) {
if (parent_index == G_to[index][j... | 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 int N = 1e5 + 7;
long long int ord[3 * N] = {0}, visit[3 * N] = {0}, indeg[3 * N] = {0}, f = 0;
vector<long long int> ans[2 * N];
map<pair<long long int, long long int>, long long int> mp;
void dfs(vector<long long int> vec[], long long int a) {
long 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;
vector<int> day;
void dfs(int src, vector<vector<pair<int, int>>> &adj, int dont = 0,
int par = -1) {
int cur = 1;
for (auto &x : adj[src]) {
if (x.first == par) continue;
if (cur == dont) cur++;
day[x.second] = cur;
dfs(x.first, adj, cur, src);... | 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;
struct node {
int v, next, num;
} e[maxn << 1];
int n;
int cnt, head[maxn];
inline void add(int x, int y, int num) {
e[++cnt].v = y;
e[cnt].next = head[x];
head[x] = cnt;
e[cnt].num = num;
}
int du[maxn], ans;
vector<int> pth[maxn];
void... | 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;
map<pair<int, int>, int> edge_no;
int max_day = 0;
vector<int> build_schedule[200001];
void addEdge(vector<int> adj[], int u, int v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
void DFSUtil(int u, vector<int> adj[], vector<bool> &visited, int day) {
visited[u] = tru... | 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;
std::vector<pair<int, int>> adj[200005];
std::vector<int> ans[200005];
void dfs(int n, int u, int v) {
int j = 1;
for (auto i : adj[n]) {
if (j == v) j++;
if (i.first != u) {
ans[j].push_back(i.second);
dfs(i.first, n, j);
j++;
}
}
retu... | 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> day;
void dfs(int v, int edge) {
for (int i = 0, d = 0; i < g[v].size(); ++i, ++d) {
if (g[v][i].second == edge) {
--d;
continue;
}
if (edge >= 0 && d == day[edge]) ++d;
day[g[v][i].second] = 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;
int n;
vector<pair<int, int> > edge[MAXN + 5];
int ind[MAXN + 5];
vector<int> ans[MAXN + 5];
inline void OPEN(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void dfs(int u, int fa, int No) {
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 MAXN = 200000;
int n, degree[MAXN];
vector<pair<int, int> > edges[MAXN];
vector<vector<int> > answers;
void dfs(int u, int parent, int day) {
int dayIdx = 0;
for (auto &edge : edges[u])
if (edge.first != parent) {
dayIdx += dayIdx == day;
if (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.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
public class RoadImp{
private static void dfs(Node[] nodes, int n, HashMap<Integer, List<Integer>> res, int cur, int parentLabel, HashSet<Integer>... | 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;
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>
using namespace std;
void boost() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 2e5 + 5;
vector<int> day[N];
int l[N], r[N];
vector<pair<int, int> > adj[N];
void dfs(int u, int p) {
for (auto v : adj[u]) {
if (v.first != p) {
if (l[u] - 1 > 0) {
l[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 lim = (int)(2e5 + 5);
int n, ans;
vector<pair<int, int> > v[lim];
vector<int> vec[lim];
void dfs(int x, int back, int y) {
int cn = 0;
for (int i = 0; i < (int)v[x].size(); i++) {
if (v[x][i].first == back) continue;
cn++;
if (cn == y) cn++;
an... | 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 |
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.BigInteger;
import java.util.Map.Entry;
import static java.lang.Math.*;
public class C extends PrintWriter {
class Road {
final int id, dst;
Road ret;
public Road(int id, int dst) {
this.id = id;
this.dst = dst;
}
}
void run() {
int n = next... | 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.OptionalInt;
import java.util.ArrayList;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
... | 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>> G[200005];
vector<int> ans[200005];
void dfs(int n, int p, int dayp) {
int k = 1;
for (auto z : G[n]) {
if (z.first != p) {
if (k == dayp) k++;
ans[k].push_back(z.second);
dfs(z.first, n, k);
k++;
}
}
}
int main()... | 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) {
int cnt = 0;
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i].first, num = adj[u][i].second;
if (v == par) 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.*;
import java.util.*;
public class tests {
Fs scn = new Fs(System.in);
int n = scn.nextInt();
ArrayList<Pair>[] graph = new ArrayList[n];
boolean[] used = new boolean[n];
ArrayList<Pair2> pars = new ArrayList<>();
PrintWriter out = new PrintWriter(System.out);
public stat... | 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 = 9e5 + 6;
int ans[N];
vector<pair<int, int> > G[N];
vector<int> aa[N];
int n;
void dfs(int x, int f, int c) {
int st = 1;
for (auto k : G[x]) {
if (k.first != f) {
if (st == c) st++;
ans[k.second] = st;
dfs(k.first, x, st);
++st;... | 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[200005];
vector<pair<int, int> > adj[200005];
int n, a, b, tot;
void dfs(int pos, int par, int used) {
int start = 0, baby, path, j;
for (int i = 0; i < adj[pos].size(); i++) {
baby = adj[pos][i].first;
path = adj[pos][i].second;
if (baby != pa... | 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 = 200010;
vector<int> g[MAX];
vector<int> ans[MAX];
int rootId = 0;
int rootPow = 0;
map<pair<int, int>, int> m;
int bad[MAX];
bool used[MAX];
void dfs(int v, int parent) {
if (used[v]) {
return;
}
used[v] = true;
int sz = (g[v].size());
int 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.*;
public class Main {
static int MOD = 1000000007;
// After writing solution, quick scan for:
// array out of bounds
// special cases e.g. n=1?
//
// Big numbers arithmetic bugs:
// int overflow
// sorting, or tak... | 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 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 | 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 {
public static void main(String[] args) {
InputReader inputReader = new InputReader(System.in);
PrintWriter printWriter =... | 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 maxn = 2e5 + 5;
int n;
vector<pair<int, int>> g[maxn];
vector<int> ans[maxn];
int tot;
void dfs(int u, int fa, int ti) {
int cur = 0;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i].first;
if (v == fa) continue;
if (++cur == ti) 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;
int n;
vector<int> res[200009];
vector<pair<int, int> > path[200009];
int last[200009];
queue<pair<int, int> > Q;
int main() {
cin >> n;
int a, b;
for (int i = 1; i < n; i++) {
scanf("%d%d", &a, &b);
path[a].push_back({b, i});
path[b].push_back({a, 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 N = 2e5 + 5;
vector<pair<long long, long long> > adj[N];
long long deg[N];
vector<long long> ans[N];
long long anss[N];
void dfs(long long u, long long p, long long prev) {
long long curr = 1;
for (auto k : adj[u]) {
if (k.first == p) continue;
if (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;
int gcd1(int a, int 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) % 1000000007LL;
val = (val * val) % 1000000007LL;
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 MAXN = 200 * 1000 + 20;
bool mark[MAXN];
int n, x, y, g;
vector<pair<int, int>> gr[MAXN];
vector<int> ans[MAXN];
void dfs(int v, int u, int g) {
int h = 1;
for (pair<int, int> i : gr[v]) {
if (i.first != u) {
if (h == g) h++;
ans[h].push_back(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;
struct Edge {
int u, id;
Edge(int _u, int _id) {
u = _u;
id = _id;
}
};
vector<Edge> to[200005];
vector<int> ans[200005];
int skp[200005];
void dfs(int v, int p) {
int s = 1;
for (auto x : to[v]) {
if (x.u == p) continue;
s += (skp[v] == s);
an... | 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;
vector<vector<pair<int, int>>> res;
void dfs(int node, int parent, int day_parent) {
int cnt = 0;
for (auto neighbor : g[node]) {
if (neighbor == parent) continue;
if (cnt == day_parent) cnt++;
if (cnt >= res.size()) res.push_back(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;
vector<vector<pair<int, int> > > vec;
vector<vector<int> > ans;
void w(int v, int u, int k) {
int k2 = 1;
for (int i = 0; i < vec[v].size(); ++i) {
if (k2 == k) {
++k2;
}
if (vec[v][i].first == u) {
continue;
}
ans[k2].push_back(vec[v][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> > gr[200005];
vector<int> ans[200005];
int mx;
void dfs(int v, int pr, int day) {
int cd = 0;
for (auto &i : gr[v]) {
if (i.first == pr) continue;
while (++cd == day)
;
mx = max(mx, cd);
ans[cd].push_back(i.second);
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;
const int maxn = 3e5;
struct edge {
int to, id;
};
vector<edge> g[maxn];
vector<int> res[maxn];
void dfs(int v, int p, int f) {
int c = 0;
for (auto &e : g[v]) {
if (e.to == p) {
continue;
}
if (c == f) {
++c;
}
res[c].push_back(e.id);
... | 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; ++i) {
int u, v;
cin >> u >> v;
g[u].emplace_back(v, i);
g[v].emplace_back(u, i);
}
vector<vector<int>> ans(n + 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 N = 2e5 + 5;
int n, res;
bool visited[N];
vector<pair<int, int> > adj[N];
vector<int> output[N];
void Input() {
cin >> n;
for (int i = 1; i <= n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(make_pair(v, i));
adj[v].push_back(make_pair(... | 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 read() {
int x = 0, fh = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') fh = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * fh;
}
const int maxn = 2e5 + 5;
... | 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;
int n;
vector<int> v[maxn];
vector<pair<int, int> > g[maxn];
set<int> s;
int color[maxn];
int ans;
void dfs(int v, int par = 0, int c = n) {
s.erase(c);
for (auto u : g[v])
if (u.first != par) {
color[u.second] = *s.begin();
s.er... | 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 = 1000 * 1000 * 2;
vector<pair<int, int>> gr[MAXN];
vector<int> ans[MAXN];
int check[MAXN];
void dfs(int, int);
int main() {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
gr[u].push_back({v, i});
gr[v].push_back... | 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 = 2000 * 100 + 10;
int n, d;
vector<int> ans[N];
vector<pair<int, int>> adj[N];
void dfs(int root, int par = -1, int prv = 0) {
int nxt = 1;
for (auto u : adj[root])
if (u.first ^ par) {
if (nxt == prv) nxt++;
ans[nxt].push_back(u.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 maxn = 5e5 + 10;
int f[maxn], color[maxn];
vector<pair<int, int> > g[maxn];
vector<int> vmark[maxn];
int n;
void input() {
int z = 1;
cin >> n;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(make_pair(y, z));
g[y].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.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
new Main().run(in, out);
out.close();
}
// should be the max(ind... | 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 int INF = 1e9 + 5;
long long int mod = 998244353;
long long int nax = 2e5;
vector<vector<long long int>> g(nax + 1), days(nax + 1);
map<pair<long long int, long long int>, long long int> mp;
void dfs(long long int node, long long int pa, long long int k,
... | 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, id;
};
int n, a, b, r;
vector<edge> g[200009];
vector<int> ret[200009];
void dfs(int pos, int pre, int pid) {
int curid = 0;
for (edge e : g[pos]) {
if (e.to != pre) {
if (pid == curid) curid++;
ret[curid].push_back(e.id);
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.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.util.TreeMa... | 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, ans;
vector<int> v[200010], v_ans[200010];
map<pair<int, int>, int> m;
void dfs(int node, int par, int col) {
ans = max(ans, col);
int c = 1;
for (int i = 0; i < v[node].size(); i++) {
if (v[node][i] == par) continue;
if (c == col) c++;
dfs(v[node][... | 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 = 200009;
vector<pair<int, int> > g[N];
bool used[N];
vector<int> steps[N];
int u[N], v[N];
deque<int> q;
int ind[N];
bool usedTo[N];
int main() {
int n;
cin >> n;
for (int i = 1; i < n; ++i) {
scanf("%d%d", &u[i], &v[i]);
g[u[i]].push_back(make_pa... | 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>> G[200005];
vector<int> work[200005];
int mxday;
void dfs(int now, int pa, int pud) {
int nt = 1;
for (auto i : G[now]) {
if (i.first == pa) continue;
if (nt == pud) ++nt;
work[nt].push_back(i.second);
mxday = max(mxday, nt);
df... | 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 comment(linker, "/STACK:67108864")
using namespace std;
int n;
vector<int> vc[222222];
vector<int> cn[222222];
set<int, less<int> > vv[222222];
int dr[222222][2];
bool color[222222];
int mx = 0;
void dfs(int v) {
color[v] = true;
for (size_t i = 0; i < cn[v].size(); i++) {
int j... | 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;
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;
int n, k;
vector<pair<int, int> > g[200055];
vector<int> res[200055];
void dfs(int id, int par, int pre) {
int cnt = 0;
for (int i = 0; i < (int)g[id].size(); i++) {
int to = g[id][i].first, u = g[id][i].second;
if (to == par) 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;
vector<pair<long long, long long> > adj[200001];
bool visit[200001];
const int mod = 1000000007;
long long mod_mult(long long a, long long b) {
return ((a % mod) * (b % mod)) % mod;
}
long long mult(long long x, long long y) {
long long prod = 1;
while (y > 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;
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 INF = 0x3f3f3f3f;
vector<pair<int, int>> v[200001];
vector<int> ans[200000];
int k = 0;
void dfs(int cur, int pre, int tm) {
int fixtime = 0;
for (auto i : v[cur]) {
int nxt = i.first;
if (nxt == pre) continue;
++fixtime;
if (fixtime == tm) ++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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 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 qhea... | 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 double eps = 1e-7;
const double PI = acos(-1);
const long long INFF = (long long)1e18;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)2e5 + 7;
vector<pair<int, int> > edge[MAX];
vector<int> ans[MAX];
int ck[MAX];
void dfs(int u, int pa, 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 sys
mx=2*10**5+10
g=[[] for _ in range(mx)]
days=[[] for _ in range(mx)]
maxi=-1
n=int(raw_input())
t=sys.stdin.read().split("\n")
for i in range(n-1):
l=t[i]
u,v=map(int,l.split())
g[u].append((v,i+1))
g[v].append((u,i+1))
q=[(1,1,-1) for i in range(n)]
h,t=0,1
while h<t:
u,pu,c=q[h][0],q[h][1],... | 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>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 200000;
vector<pair<int, int> > g[N];
int depth[N], pa[N];
void dfs(int u, int par, int d) {
pa[u] = par;
depth[u] = d;
for (pair<int, int>& i : g[u])
if (i.first != par) dfs(i.first, u, d + 1);
}
void solve() {
int 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;
const int N = 2e5 + 25;
int n, u, v, res;
vector<pair<int, int> > G[N];
vector<int> ans[N];
void dfs(int u, int p, int last) {
res = max(res, (int)G[u].size());
int cnt = 0;
for (int i = 0; i < G[u].size(); ++i) {
int v = G[u][i].first;
if (v == p) 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.ArrayList;
import java.util.StringTokenizer;
public class Main {
static MyScanner in;
static PrintWriter out;
// static Timer timer = new Timer();
public static void main(String[] args) throws IOException {
in = new MyScanner();
out = new PrintWrite... | 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.*;
import java.util.*;
public class MyClass {
public static void main(String args[]) throws IOException{
Scan sc = new Scan();
int n = sc.scanInt();
Solution sol = new Solution(n);
for(int i = 1; i < n; ++i){
sol.addEdge(i, sc.scanInt(), sc.scanInt());
}
... | 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.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.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayLis... | 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 = 2 * 100 * 1000 + 7;
int n, cou;
int arr_p[N], color[N], a[N];
vector<int> ans[N];
pair<int, int> road[N];
vector<int> gr[N];
int f(int);
void dfs(int);
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
int x, y;
for (int 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 Max = 2e5;
vector<pair<int, int> > G[Max + 5];
vector<int> ans[Max + 5];
int n;
int sum;
void dfs(int x, int fa, int t) {
int k = 0;
for (int i = 0; i < G[x].size(); i++) {
if (G[x][i].first == fa) continue;
k++;
if (k == t) k++;
dfs(G[x][i].fi... | 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 int N = 1000001;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<pair<int, int>> a[n + 1];
int ans = 0;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
a[u].push_back(make_pai... | 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 dp[N];
int n, a, b;
vector<pair<int, int> > g[N];
vector<int> ans[N];
void dfs(int v, int p = -1, int d = -1) {
int cnt = 0;
for (int(i) = (0); i < (g[v].size()); ++(i)) {
int to = g[v][i].first;
if (to == p) continue;
if (cnt == 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 = 200010;
vector<pair<int, int> > G[maxn];
vector<int> res[maxn];
int cnt = 0;
void dfs(int v, int p, int x) {
int vl = 1;
if (vl == x) {
++vl;
}
for (int i = 0; i < (int)G[v].size(); ++i) {
int u = G[v][i].first;
if (u != p) {
res[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;
int n;
const int maxn = 2e5 + 10;
struct node {
int next, v, num;
} e[maxn * 2];
int tot, head[maxn];
vector<int> ans[maxn];
int du[maxn];
void add(int x, int y, int num) {
e[++tot].v = y;
e[tot].next = head[x];
e[tot].num = num;
head[x] = tot;
}
void dfs(int u, 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 N = 200010;
vector<pair<int, int> > g[N];
vector<int> r[N];
int d[N];
void dfs(int u, int fa, int x) {
int c = 0;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i].first;
if (v == fa) continue;
c++;
if (c == x) c++;
r[c].push_back(g[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>
void quit();
using namespace std;
const long double PI = acos(-1);
const long double EPS = 1e-10;
double __t;
int n;
int d[200100];
vector<pair<int, int> > g[200100];
int day[200100];
vector<int> ans[200100];
void dfs(int v, int skip = -1) {
int cnt = 0;
for (auto &e : g[v]) {
if (day[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;
int gcd1(int a, int 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) % 1000000007LL;
val = (val * val) % 1000000007LL;
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;
vector<vector<pair<int, int> > > graph;
vector<vector<int> > ans;
int maxDeg;
int root;
void dfs(int u, int p, int day) {
int add = 1;
for (int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i].first;
int id = graph[u][i].second;
if (v == p) 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;
vector<vector<int> > edge(200005, vector<int>());
vector<vector<int> > ans(200005, vector<int>());
vector<bool> visited(200005, false);
map<pair<int, int>, int> mp;
void dfs(int i, int num) {
visited[i] = true;
int it = 1;
for (auto ed : edge[i]) {
if (!visited[ed... | 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, in[200005], day[200005];
vector<int> ans[200005];
vector<pair<int, int> > adj[200005];
void dfs(int now, int pre) {
map<int, int> M;
for (int i = 0; i < adj[now].size(); i++) {
int road = adj[now][i].second;
if (day[road]) {
M[day[road]] = 1e9;
... | 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> > adj[maxn];
vector<int> v[maxn];
bool visit[maxn];
int n, m, u, v1, ans;
long long modx(long long base, long long ex) {
long long ans = 1LL, val = base;
while (ex > 0LL) {
if (ex & 1LL) ans = (ans * val) % 1000000007... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.