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
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, vis[500010]; int cur[500010]; vector<int> G[500010]; vector<int> bbc[500010]; queue<int> Q; queue<int> X; int check(int x, int y) { int L = 0, R = G[x].size() - 1; while (L <= R) { int M = (L + R) / 2; if (G[x][M] == y) { return 1; } else if ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, x, y, T, ans, big, cas, num, len; bool flag; vector<int> G[500005], out[500005]; set<int> st; void bfs(int u) { queue<int> q; q.push(u); while (!q.empty()) { u = q.front(); q.pop(); out[ans].push_back(u); for (set<int>::iterator it =...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.List; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.ArrayList; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.TreeSet; import java.util.StringTokenizer; import java.math.BigInteger; impor...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = getchar(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int const MN = 5e5 + 100; int n, m, c; vector<int> ans[MN], vis, adj[MN]; bool mark[MN]; queue<int> q; int main() { scanf("%d %d", &n, &m); for (int i = 0, u, v; i < m; i++) { scanf("%d %d", &u, &v); u--, v--; adj[u].push_back(v); adj[v].push_back(u); ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adjlist; int main() { int n, m; scanf("%d %d", &n, &m); adjlist.assign(n, vector<int>()); for (int i = 0; i < m; ++i) { int a, b; scanf("%d %d", &a, &b); a--; b--; adjlist[a].push_back(b); adjlist[b].push_back(a); } m...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.io.InputStream; /** * TEST * * Built using CHelper plug-in * Actual solution is at the top * @author Al...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 500 * 1000 + 100; const long long mod = 1e9 + 7; const long long inf = 2 * 1e18; long long n, m, sz; vector<int> com[maxn]; vector<int> adj[maxn]; set<int> un_marked; bool mark[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const long double eps = 1e-07; int n, m; vector<int> g[501000]; int p[501000]; int sz[501000]; set<int> vv; int getanc(int v) { if (v == p[v]) return v; return p[v] = getanc(p[v]); } void merge(int a, int b) { int x = getanc(a); int y = g...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.util.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { int g [][]; int deg []; int edges [][]; ArrayList<ArrayList<Integer>> answer = new ArrayList<ArrayList<Integer>>(); public void solve () throws Ex...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const long long LNF = 1e18; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100 * 1000 + 14; vector<int> comp[MAXN], adj[MAXN]; set<int> res; int ans = 0; void dfs(int v) { comp[ans].push_back(v); auto it = res.begin(); while (it != res.end()) { if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) { int ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; ll power(ll x, ll y); const ll MOD = 1e9 + 7; const ll INF = 1e18 + 18; const int inf = 2e9; const int N = 5e5 + 5; vector<int> v[N]; vector<int> adj[N]; vector<int> res; set<int> st; int bfs(int s) { ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collection; import java.util.InputMismatchException; import java.io.IOException; import java.util.Random; import java.util.ArrayList; import java.util.NoSuchElementE...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; inline long long modadd(long long n, long long m, long long p = 998244353) { return ((n + m) % p + p) % p; } inline long long modsub(long long n, long long m, long long p = 998244353) { return ((n - m + p) % p + p) % p; } inline long long modpro(long long n, long long m...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 1; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; set<pair<int, int> > st; set<int> ML[N]; vector<int> adj[N]; bitset<N> B; int n, m, a, b, tmp, x, D[N]; pair<int, int> p, p2; bool C(int a, int b...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
// package cf190; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.util.function.IntConsumer; import java.util.stream.Collectors; public class CFE { private static final long MOD = ...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 100; template <typename T> inline T read() { T s = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { s = (s << 3) + (s << 1) + ch - 48; ch = getchar(); } ret...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> e[500500]; vector<int> res[500500]; bool visited[500500]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--; v--; e[u].push_back(v); e[v].push_back(u); } list<int> s...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Task2 { public static void main(String[] args) throws IOException { new Task2().solve(); } int mod = 1000000007; PrintWriter out; int n; int m; ArrayList<Integer>[] g;...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; set<int> ss1; set<int>::iterator pos; vector<int> g[500010]; queue<int> q; struct Edge { int v, pre; }; Edge e[2000010]; int use[500010]; int ecnt, hh[500010], p[500010]; void addEdge(int u, int v) { e[ecnt].v = v; e[ecnt].pre = hh[u]; hh[u] = ecnt++; } int main() {...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 500 * 1000 + 10; int n, m, cnt; set<int> sv; vector<int> adj[N], ans[N], tmp; queue<int> q; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> n >> m; for (int i = 0, u, v; i < m; i++) cin >> u >> v, adj[u].push_back(v), ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 500050; set<int> Free; vector<int> E[N], sol[N]; void DFS(int u, int c) { Free.erase(u); sol[c].push_back(u); int nxt = N; for (int i = (signed)E[u].size() - 1; ~i; i--) { for (int v = *Free.upper_bound(E[u][i]); v < nxt; v = *Free.upper_b...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; constexpr int N = 1e6 + 10; int n, m, pos, u, v, z, ver, mn, mx; vector<int> ans[N]; vector<pair<int, int>> edge; deque<int> ve; bool mark[N]; bool bin(int b, int e) { if (b + 1 == e) { if (edge[b].first == mn && edge[b].second == mx) return false; return true; ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int n, m; const int maxN = 5e5 + 5; vector<int> g[maxN]; set<int> a; vector<vector<int>> ans; void dfs(int node) { a.erase(a.find(node)); ans.back().push_back(node); for (int i = 0; i < g[node].size(); i++) { auto it = a.lower_bound(g[node][i] + 1); while (it ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 10; const int maxn = 5e5 + 30; const int maxq = 1e5 + 10; const int alf = 26; const long long dlm = 1e9 + 7; const long long del = 179425601; const int eps = 1e-7; string O[] = {"YES", "NO", "Yes", "No"}; vector<int> g[maxn]; int com1[maxn], pr[...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.util.*; public class Main { static FastReader in; static PrintWriter out; static int n, m; static int[][] edges; static int[] deg; static int[][] g; static HashSet<Integer> s; static LinkedList<Integer> q; static ArrayList<ArrayList<Integer>> ans; ...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; vector<int> adj[N]; set<int> st, tmp; vector<int> ans[N]; queue<int> q; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); u--, v--; adj[u].push_back(v); adj[v].push...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; void dfs(int s, set<int> &v, set<pair<int, int>> &edge, vector<int> &nodes) { v.erase(s); nodes.push_back(s); vector<int> q; for (auto i : v) { if (edge.count({min(i, s), max(i, s)}) == 0) { q.push_back(i); } } for (auto i : q) v.erase(i); for (a...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 5000 * 100 + 5; const int mod = 1000 * 1000 * 1000 + 7; vector<int> nadj[maxn]; vector<int> comp[maxn]; int par[maxn]; int h[maxn]; int tmp[maxn]; int getpar(int x) { if (par[x] == x) return x; par[x] = getpar(par[x]); return par[x]; } void join(int u...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 500100; unordered_set<int> grafo[MAXN], s; vector<int> vec; void dfs(int x) { vec.push_back(x); vector<int> v; for (auto i : s) { if (grafo[x].find(i) != grafo[x].end()) continue; v.push_back(i); } for (int i = 0; i < v.size(); i++) s.eras...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.util.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { int g [][]; int deg []; int edges [][]; ArrayList<ArrayList<Integer>> answer = new ArrayList<ArrayList<Integer>>(); public void solve () throws Ex...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 2e18; int st, cmp[maxn5], nxt[maxn5], pre[maxn5]; vector<int> adj[maxn5], ver[maxn5]; bool mark[maxn5]; void...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> v[500005], sol[500005], to_del; int DUMMY1 = 0, DUMMY2 = 500005; struct lista { int pr, nx, apare; } ls[500010]; inline void sterge(int val) { int pre = ls[val].pr; int nxt = ls[val].nx; ls[pre].nx = nxt; ls[nxt].pr = pre; ls[val].apare = 0; } inline...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
//package round120; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.InputMismatchException; import java.util.Map; public class E { InputStream is; PrintWriter out; String INPU...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int n, m; int fa[500010], ind[500010]; struct node { int to, next; } edge[500010 * 10]; int head[500010], sumedge, poi[500010], tot, pos[500010]; int cnt, num[500010]; vector<int> v[500010]; bool used[500010], g[2005][2005]; map<pair<int, int>, bool> mmm; int getfa(int x)...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> const double eps = 1e-10; using namespace std; using ll = long long; using ul = unsigned long long; using PII = pair<int, int>; const int NN = 1011101; const int NZ = 511100; const int MM = 151; const int need = (1 << 30) - 1; int n, m, s, x, i, j, t, a, b, k, c, r, col[NN]; int l; ll in[NN]; i...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5; int n, m, mind, sub[maxn + 10], br, no_edge[maxn + 10], par[maxn + 10], sz[maxn + 10]; vector<int> vect[maxn + 10], rez[maxn + 10]; vector<int> mapa[maxn + 10]; int fnd(int x, int y) { int l = 0; int r = mapa[x].size() - 1; int sr; int ret ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 10, M = 1e6 + 100, MOD = 1e9 + 7, ML = 25; int a[M], ne[M]; vector<int> ve[M], adj[M]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; long long int n, m; vector<long long int> a[500005]; set<long long int> vis; vector<vector<long long int> > ans; vector<long long int> vv; inline void dfs(long long int node) { vis.erase(node); vv.push_back(node); long long int cur = 0; while (!vis.empty()) { au...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const long long LNF = 1e18; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); } const int N = 5e5 + 7; set<int> unvis; unordered_set<int> adj[N]; vector<vector<int> > ans; void dfs(int u) { ans.back().emplac...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
//package prac; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Round120E { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.*; import java.io.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; public class CounterAttack { private static InputReader in; private static PrintWriter out; public static void main(String[] args) { new CounterAttack().run(...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 10; vector<int> cc[MAX_N]; vector<int> adj[MAX_N]; vector<int> rem; set<int> seen; queue<int> q; void bfs(int u, int num) { q.push(u), seen.erase(u); cc[num].push_back(u + 1); while (((int)(q).size())) { u = q.front(); rem.clear(); ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collection; import java.util.InputMismatchException; import java.io.IOException; import java.util.Random; import java.util.NoSuchElementException; import java.io.Inp...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 2e18; int st, cmp[maxn5], nxt[maxn5], pre[maxn5]; vector<int> adj[maxn5], ver[maxn5]; bool mark[maxn5]; void...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> int power(int a, int b) { int z = 1; while (b) { if (b & 1) { z *= a; z %= 1000000007; } a *= a; a %= 1000000007; b /= 2; } return z % 1000000007; } using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m, a, b; ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100 * 1000 + 14; vector<int> comp[MAXN], adj[MAXN]; set<int> res; int ans = 0; void dfs(int v) { comp[ans].push_back(v); auto it = res.begin(); while (it != res.end()) { if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) { int ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, m, ind[N]; vector<int> adj[N]; bool interest[N]; vector<vector<int> > cc; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; void scout(int u) { for (int x : adj[u]) if (interest[x])...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const int N = 5e5 + 7; bool flag; vector<int> G[N], out[N]; set<int> st; int res; void bfs(int u) { queue<int> que; que.push(u); while (que.size()) { int f = que.front(); que.pop(); ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; long long int const inf = 1e18; long long int const maxn = 1e6 + 5; long long int const mod = 1e9 + 7; set<int> unvisited; vector<pair<int, int>> v; int cur = 0; vector<int> components[maxn]; pair<int, int> fx(int x, int y) { return make_pair(min(x, y), max(x, y)); } void d...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 500005, M = 1e6 + 5; int g[N]; vector<int> a[N], ans[N]; int FIND(int x) { return g[x] == x ? x : g[x] = FIND(g[x]); } void UNION(int x, int y) { g[FIND(x)] = FIND(y); } int main(void) { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) g[i] ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, M = 1e6 + 10; vector<int> g[N]; vector<vector<int> > ans; bool mark[N]; set<int> st; int dfs(int v) { mark[v] = 1; int ans = 1; for (auto u : g[v]) { if (!mark[u]) ans += dfs(u); } return ans; } vector<int> bfs(int s) { queue<int> q; ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const long long mx = 5000 * 100 + 5; set<long long> ms, msp; vector<long long> ad[mx], cm[mx]; queue<long long> q; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, u, v, c = 0; cin >> n >> m; for (long long i = 0; i < m...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000 + 100; vector<int> mp[MAXN], ans[MAXN]; int n, m, cnt = 0, f[MAXN]; int F(int x) { return f[x] != x ? f[x] = F(f[x]) : f[x]; } void dfs(int x) { ans[cnt].push_back(x); f[x] = x + 1; for (int j = 0, i = F(1); i <= n; i = F(i + 1)) { j = lowe...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const long long N = 500005, INF = 2000000000000000000; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>= 1; a = (a * a) % p; } return res; }...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 1000; vector<int> adj[MAXN], com[MAXN]; int nxt[MAXN]; bool mark[MAXN]; int n, m; int fnxt(int x) { return nxt[x] == x ? x : nxt[x] = fnxt(nxt[x]); } void dfs(int v, int cnt) { mark[v] = true; nxt[v] = v + 1; com[cnt].push_back(v); for (int i ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; set<int> s; set<pair<int, int> > m; vector<int> ans[500005]; void dfs(int i, int c) { s.erase(i); ans[c].push_back(i); auto it = s.begin(); while (it != s.end()) { int y = *it; if (m.find(make_pair(min(i, y), max(i, y))) == m.end()) dfs(y, c); it = s.upp...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> int n, m, c[500001]; std::set<std::pair<int, int>> e; std::set<int> unvis; std::vector<int> ans[500001]; void Bfs(int s) { std::queue<int> q; q.emplace(s); c[s] = s; while (!q.empty()) { int u = q.front(); q.pop(); for (auto it = unvis.begin(); it != unvis.end(); ++it) { ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> const int N = 500010; const int inf = 0x3f3f3f3f; using namespace std; int n, m; int vis[N]; bool q[N]; set<int> st; int l[N]; vector<int> vt[N], ret[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); vt[a].push_back(b); vt...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n, m, a, b; vector<vector<int> > results; set<pair<int, int> > edges; set<int> nodes; ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> a >> b; a--; b--; edges.insert(ma...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.*; import java.io.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; public class CounterAttackDSU { private static InputReader in; private static PrintWriter out; public static void main(String[] args) { new CounterAttackDSU(...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 5; vector<int> adj[MAXN]; int n, m; int p[MAXN]; vector<int> c[MAXN]; bool is[MAXN]; int root(int v) { if (p[v] == -1) { return v; } return p[v] = root(p[v]); } void merg(int v, int u) { v = root(v); u = root(u); if (c[v].size() < c[u]...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5000 * 100 + 5; int n, m, cnt, c; set<int> st, bkst; vector<int> adj[N], ans[N]; bool flag; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> n >> m; for (int i = 1; i <= n; i++) st.insert(i); for (int i = 1, v, u; i ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.io.InputStream; /** * TEST * * Built using CHelper plug-in * Actual solution is at the top * @author Al...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int Distance[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; const int Nmax = 500100; int n, m; vector<vector<int> > g; queue<int> que; set<int> unUsed; int d[Nmax]; inline void add(int vertex, int color) { d[vertex] = color; unUsed.erase(vertex); que.push(vertex); ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.util.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { int g [][]; int deg []; int edges [][]; ArrayList<ArrayList<Integer>> answer = new ArrayList<ArrayList<Integer>>(); public void solve () throws Ex...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int M = 5 * 100000; const int N = 1e6; vector<int> adj[N]; vector<int> ans[M]; set<int> s; int cnt, n, m; queue<int> q; bool mark[M]; void bfs(int x) { q.push(x); s.erase(x); mark[x] = true; while (!q.empty()) { ans[cnt].push_back(q.front()); int u = q...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; const int INF = 1e9 + 7; const int MOD = 1e6 + 3; const double Pi = acos(-1.0); const double EPS = 1e-8; int n, m, f[N]; vector<int> e[N]; inline int get(int x) { int r, t = x; while (t != f[t]) t = f[t]; r = t, t = x; while (t != f[t]) x = f[...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int mxn = 1e6 + 5; set<pair<int, int> > st; set<int> a; vector<int> ans[mxn]; int n, m, x, y, t, de[mxn]; void bfs(int v) { int s = *a.begin(); queue<int> q; ans[t].push_back(v); a.erase(v); q.push(v); while (q.size()) { int u = q.front(); q.pop();...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.*; import java.io.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; public class CounterAttackDSU { private static InputReader in; private static PrintWriter out; public static void main(String[] args) { new CounterAttackDSU(...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 100; vector<int> vv[N], tmp; int f[N]; void fun(int x, int y) { int ex = vv[x].size(); int ey = vv[y].size(); tmp.clear(); for (int i = 0, j = 0; i < ex; i++) { while (j < ey && vv[y][j] < vv[x][i]) j++; if (j < ey && vv[y][j] == vv[x][i]...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.util.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { int g [][]; int deg []; int edges [][]; public void solve () throws Exception { int n = nextInt(); int m = nextInt(); g = new int [n][]; deg ...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int M = 500000 + 10; vector<int> adj[M]; set<int> S; vector<int> compo[M]; queue<int> Q; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } for (in...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 5e5 + 5; vector<int> v[N], tmp; vector<vector<int>> ans; set<int> st; bool ok(int node, int x) { return !binary_search(v[node].begin(), v[node].end(), x); } void dfs(int cur) { tmp.push_back(cur); vector<int> let; for (int x : ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 500 * 1000 + 10, maxm = (1 << 17), mod = (int)1e9 + 7, hash = 7000001, inf = (1 << 29); const double pi = 3.14159265359, ee = 2.71828; struct node { int par, sz; bool mark; vector<int> g; } v[maxn]; vector<int> comp[maxn]; set<int> ch; int f...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.util.List; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.ArrayList; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.TreeSet; import java.util.StringTokenizer; import java.math.BigInteger; impor...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxl = 5 * 1000 * 100 + 5; vector<int> v[maxl]; int n, m; bool flg; set<int> deg[2]; bool marked[maxl]; int res; vector<int> ans[maxl]; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); a--; b-...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; set<int> unused; for (int i = 0; i < n; i++) { unused.insert(i); } vector<vector<int>> adj(n); vector<int> check(n, 0); for (int i = 0; i < m; i+...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } set<int> s; set<int>::iterator it; vector<vector<int> > com; int q[500500], qf, qb; int head[999983], ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const int N = 5e5 + 7; vector<int> G[N], res[N]; set<int> st; int sum; void bfs(int u) { queue<int> q; q.push(u); while (q.size()) { int f = q.front(); q.pop(); res[sum].push_back(f)...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100 * 1000 + 14; vector<int> comp[MAXN], adj[MAXN]; set<int> res; int ans = 0; void dfs(int v) { comp[ans].push_back(v); auto it = res.begin(); while (it != res.end()) { if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) { int ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, m, comps; set<pair<int, int> > roads; set<int> nods, components[N]; set<int>::iterator it; bool not_exist(int v, int u) { if (v > u) swap(v, u); if (roads.find({v, u}) == roads.end()) return true; else return false; } void dfs(in...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 3; unordered_set<int> adj[N], rem; vector<int> comp[N]; vector<int> del; queue<int> q; int conn, n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> m; for (int i = 1; i <= n; i++) rem.insert(i); for (int...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 2e18; int st, cmp[maxn5], nxt[maxn5], pre[maxn5]; vector<int> adj[maxn5], ver[maxn5]; bool mark[maxn5]; void...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> ans[(int)5e5 + 2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> adj[n]; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].push_back(y); adj[y]....
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int lim = 1e4, stop = 128, nmax = 5e5 + 42; int n, m; bitset<lim> edge[lim]; vector<vector<int> > outp; bitset<nmax> been, emp; void dfs(int node) { if (been[node]) return; been[node] = 1; outp[outp.size() - 1].push_back(node); for (int i = 1; i <= n; i++) ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 5 * 1e5 + 7; int n, m; vector<int> g[maxn]; bool vis[maxn]; vector<int> ans[maxn]; int co; struct node { int u; node *nxt; } * head; int sum; void del(node *cmp) { cmp->nxt = cmp->nxt->nxt; } void bfs() { co++; queue<int> q; node *cmp; cmp = hea...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double eps = 1e-6; const int mod = (int)1e9 + 7; const int N = 4 * (int)1e4 + 5; const int sz = (int)1 << 19; int cnt = 0, x, y, n, m, hm; vector<int> comp[500500], g[500500]; bitset<500500> b; int t[sz + sz + 100]; inline void upd(int x, int...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> const int NMAX = 100666; using namespace std; const int INF = 1000000007; vector<int> G[500555]; set<int> S; bool viz[500555]; vector<int> comps[500555]; int q[500555]; int a, b, n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); scanf("%d%d", &n, &m); for (int i = 1; i <= m; ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; long long int t, n, m; set<long long int> vis; queue<long long int> q; vector<long long int> temp, v[500005], g[500005]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int i, j, k, x, y; cin >...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 500001; int n, m, k, l, pv; set<int> s; queue<int> q; vector<int> g[MAXN], jj[MAXN], co; void bfs(int v) { q.push(v); s.erase(v); jj[pv].push_back(v); int x; while (!q.empty()) { x = q.front(); q.pop(); for (int itt : s) if (lowe...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const long long LNF = 1e18; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); } const int N = 5e5 + 7; set<int> unvis; vector<int> adj[N]; vector<vector<int> > ans; void dfs(int u) { ans.back().emplace_back(...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 1000 + 100; set<int> head; int par[MAXN], n, m, mn = MAXN, maxD, sz[MAXN]; vector<int> n_def, nb[MAXN]; void init() { for (int i = 0; i < n; i++) { par[i] = i; head.insert(i); sz[i] = 1; } } int find_par(int x) { if (x == par[x]) re...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; struct edge { int u, v; edge(){}; edge(int u, int v) : u(u), v(v){}; } e[1000100 * 2]; int qu[5 * 1000010]; int nex[5 * 1000010], pre[5 * 1000010], connect[5 * 1000010], start[5 * 1000010], stop[5 * 1000010]; bool fr[5 * 1000010]; vector<vector<int> > ans; int N, ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> ans[500010]; set<pair<int, int> > edges; set<int> unused; queue<int> q; int id = 1; void BFS() { if (q.empty()) return; int u = q.front(); q.pop(); for (set<int>::iterator it = unused.begin(); it != unused.end();) { set<int>::iterator next = it; ...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10; int c[MAXN]; vector<int> g[MAXN], com[MAXN], ans, r; inline void mer(int v, int u) { if (c[v] == c[u]) return; v = c[v]; u = c[u]; if (com[v].size() > com[u].size()) swap(v, u); while (!com[v].empty()) { int t = com[v].back(); co...
CPP
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static class FastReader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Fas...
JAVA
190_E. Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d...
2
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 500000 + 20; vector<int> adj[MAX_N]; int st[MAX_N]; int par[MAX_N]; set<int> D; vector<int> seq[MAX_N], ver; pair<int, int> minDeg; int n, m; int edge(int v, int u) { vector<int>::iterator it = lower_bound(adj[v].begin(), adj[v].end(), u); return (it =...
CPP