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 |
|---|---|---|---|---|---|
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long val = in.nextLong();
long res = 6 * val * val - 6 * val + 1;
System.out.println(res);
}
} | JAVA |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | #include <bits/stdc++.h>
int main() {
int a;
scanf("%d", &a);
long long ans = 1;
for (int i = 1; i < a; ++i) ans += 12LL * i;
printf("%I64d\n", ans);
return 0;
}
| CPP |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int a;
int main() {
cin >> a;
cout << 6 * a * (a - 1) + 1 << endl;
return 0;
}
| CPP |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | print(1+sum(12*i for i in range(1,int(input())))) | PYTHON3 |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | n=input()
sum=1
for i in range(1,n):
sum+=12*i
print sum | PYTHON |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | import math
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
n = inp()
print(n*(n-1)*6 + 1) | PYTHON3 |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | def star(n, starn_prev):
if n == 1:
return 1
elif n == 2:
return 13
else:
return starn_prev + 18 + 6 * (1 + 2 * (n - 3))
class CodeforcesTask171BSolution:
def __init__(self):
self.result = ''
self.a = 0
def read_input(self):
self.a = int(input())
... | PYTHON3 |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | k = int(raw_input())
sum = ans = 0
for i in xrange(k - 1):
sum += 12
ans += sum
print ans + 1
| PYTHON |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
long long val[18260];
void preproce() {
val[1] = 1;
for (int i = int(2); i < int(18258); i++)
val[i] = val[i - 1] + 9 * (i - 1) + 3 * (i - 1);
}
int main() {
preproce();
int n;
scanf("%d", &n);
cout << val[n] << endl;
}
| CPP |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
public static void main (String[]args)throws IOException {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(6*n*(n-1)+1);
}
}
| JAVA |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PrB {
public static long time;
public static void main(String[] args) throws Exception {
time = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(go(br));
br.... | JAVA |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int dp[20000] = {0};
dp[1] = 1;
for (int i = 2; i <= 18257; i++) dp[i] = dp[i - 1] + 12 * (i - 1);
cout << dp[n] << endl;
return 0;
}
| CPP |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | import java.io.*;
import java.lang.Math;
import java.util.*;
public class Main
{
public BufferedReader in;
public PrintStream out;
public boolean log_enabled = true;
public void test()
{
long n = readLong();
long r = 1 + 6 * n*(n-1);
out.println(r);
}
public void run()
{
try
{
in = new B... | JAVA |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr... | CPP |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | a=int(raw_input())
sum=1
for i in range(1,a):
sum+=i*12
print sum | PYTHON |
171_B. Star | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | 2 | 8 | from math import *
a= int(raw_input())
ans=1
for i in range(2,2*a,2):
ans+=6*i
print ans
| PYTHON |
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 + 1000;
vector<int> G[maxn], ans[maxn];
set<int> s;
set<int>::iterator ite;
int num[maxn], cnt, res;
void bfs(int x) {
s.erase(x);
queue<int> que;
ans[res].push_back(x);
que.push(x);
cnt = 0;
while (que.size()) {
int cur = que.front(... | 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> graph[500005];
set<int> all;
int vis[500005];
vector<int> ans[500005];
vector<pair<int, int> > sequence;
int n, m, x, y, i, cnt, k = 0;
void graph_in() {
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
scanf("%d %d", &x, &y);
graph[x].push_back(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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e >... | 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, n, m;
int ind[500010], last[1000100 * 2], e[1000100 * 2], t;
void adde(int a, int b) {
t++;
e[t] = b;
last[t] = ind[a];
ind[a] = t;
}
vector<int> nxt[2];
vector<int> pp;
int ha[500010];
int que[500010], qt;
int nt;
struct Myset {
int ind[500010];
int l... | 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 + 5;
vector<int> graf[maxn], pos[maxn];
int main() {
int n, m;
scanf("%d %d", &n, &m);
while (m--) {
int a, b;
scanf("%d %d", &a, &b);
graf[a].push_back(b);
graf[b].push_back(a);
}
for (int i = 1; i <= n; ++i) sort(graf[i].begi... | 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 = 500010;
int pa[maxn], sz[maxn];
vector<int> e[maxn];
set<int> grp, tmp;
map<int, int> lft;
int getpa(int u) { return u == pa[u] ? u : (pa[u] = getpa(pa[u])); }
int main() {
int n, m;
while (~scanf("%d%d", &n, &m)) {
grp.clear();
for (int i = 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 | 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.TreeSet;
import java.util.ArrayList;
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;
long long modpow(long long a, long long b,
long long mod = (long long)(1e9 + 7)) {
if (!b) return 1;
a %= mod;
return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const... | 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> graph[500005];
set<int> all;
int vis[500005];
vector<int> ans[500005];
vector<pair<int, int> > sequence;
int n, m, x, y, i, cnt, k = 0;
void graph_in() {
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
scanf("%d %d", &x, &y);
graph[x].push_back(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;
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 | #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> compos;
int complement_component(vector<vector<int>> &g) {
int n = g.size(), ans = 0;
set<int> S;
for (int i = 0; i < n; ++i) S.insert(i);
while (S.size()) {
++ans;
int theCompo = 0;
queue<int> q;
q.push(*S.begin());
S.erase(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 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 500005;
int n, m;
vector<int> adj[MAX];
vector<int> g[MAX];
int f[MAX];
int cnt;
int find(int u) { return f[u] = (f[u] == u) ? u : find(f[u]); }
void dfs(int u) {
f[u] = u + 1;
g[cnt].push_back(u);
for (int i = find(1), j = 0; i <= n; i = find(i + 1)) ... | 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, x, y, K;
set<int> s;
set<pair<int, int> > a;
vector<int> ans[500005];
inline void dfs(int nod) {
set<int>::iterator it;
for (it = s.begin(); it != s.end();) {
if (!a.count(make_pair(min(*it, nod), max(*it, nod)))) {
int x = *it;
s.erase(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;
int const mxn = 5e5 + 10;
vector<int> adj[mxn], v1, v2;
set<int> x, y;
vector<vector<int> > ans;
int mark[mxn];
int main() {
ios_base::sync_with_stdio(false);
int n, m, v;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].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;
int comps[500010];
set<int> notVis;
vector<vector<int> > adjList;
void dfs(int n, int cmp) {
comps[n] = cmp;
vector<int> toVis;
int idx = 0;
for (auto it = notVis.begin(); it != notVis.end();) {
while (idx < adjList[n].size() && (*it) > adjList[n][idx]) idx++;
... | 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;
set<int> ver;
int vis[500100], sz[500100], c;
vector<int> comp[500100], g[500100];
void dfs(int u, int p) {
comp[c].push_back(u);
sz[c]++;
for (int i = 0; i < g[u].size(); i++) vis[g[u][i]] = 1;
vector<int> t;
for (set<int>::iterator it = ver.begin(); it != ver.en... | 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;
int n, m, a, b, par[N], d[N], o = N, k, y, anss, cnt;
vector<int> adj[N], ans[N];
bool vis[N];
int get_par(int u) {
if (u == par[u]) return u;
return par[u] = get_par(par[u]);
}
void add(int u, int v) {
u = get_par(u);
v = get_par(v);
if (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 | //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>
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];
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;
set<int> ele[500007];
set<int> ble;
vector<int> cle[500003];
int cnt = 0, pr = 0;
void dfs(int x) {
std::vector<int> ans;
for (auto i : ble) {
if (ele[x].find(i) == ele[x].end() && ele[i].find(x) == ele[i].end()) {
ans.push_back(i);
cle[cnt].push_back(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>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 500010;
struct DSU {
int par[MAXN];
int sz[MAXN];
DSU() {
for (int i = 1; i < MAXN; 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>
#pragma GCC optimize("O3")
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 | #include <bits/stdc++.h>
using namespace std;
unordered_map<long long, int> mp;
long long temp;
vector<int> ans[500010];
int bel[500010], pre[500010], nex[500010], q[500010];
int main() {
int n, m, x, y;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
pre[i] = i - 1;
nex[i] = i + 1;
}
nex[0] = 1... | 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 + 1;
vector<vector<int> > G(MAXN);
set<int> st;
bool m_binary(vector<int> &v, int number) {
int l = 0, r = v.size() - 1;
while (l <= r) {
const int middle = (l + r) >> 1;
if (v[middle] == number) return true;
if (v[middle] < number) ... | 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 parent[500001];
int size[500001];
vector<vector<int> > neighbours;
int get_parent(int i) {
if (parent[i] == i)
return i;
else
return parent[i] = get_parent(parent[i]);
}
bool merge(int a, int b) {
int parent_a = get_parent(a);
int parent_b = get_parent(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 N = 2000 * 1000 + 2;
int n, m, x, y, cnt = 0, par[N], sum, s[N], deg[N], mo[N];
vector<int> adj[N], A, B, ans[N];
bool vis[N], is[N];
int get_par(int v) {
if (par[v] == v) return v;
return par[v] = get_par(par[v]);
}
void add(int u, int v) {
u = get_par(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 = 5e5 + 10;
set<int> rem;
queue<int> q;
vector<int> ng[MAXN];
bool mark[MAXN];
vector<int> comps[MAXN];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &x, &y);
x--;
y--;
ng[x].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;
const int MAXN = 500010;
const int inf = (1 << 30);
int n, m;
vector<int> adj[MAXN];
int p[MAXN], cmpn[MAXN];
int find(int i) { return p[i] == i ? i : p[i] = find(p[i]); }
void merge(int u, int v) {
u = find(u);
v = find(v);
p[u] = v;
}
vector<int> ans[MAXN];
bool che... | 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 + 13;
queue<int> bfsq;
set<int> bfsS;
set<pair<int, int> > forbid;
vector<int> compV[MAXN], toDel;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
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;
int n, m;
pair<int, int> edges[1000000];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < (int)(m); i++) {
int u, v;
cin >> u >> v;
edges[i] = make_pair(--u, --v);
}
sort(edges, edges + m);
set<int> a;
for (int i = 0; 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 double PI = acos(-1.0);
template <class T>
T SQR(const T &a) {
return a * a;
}
vector<int> g[500100];
int pred[500100];
vector<int> Ans[500100];
int findPred(int a) {
if (pred[a] != a) pred[a] = findPred(pred[a]);
return pred[a];
}
int P[500100] = {0};
void run(... | 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 comment(linker, "/STACK:16777216")
using namespace std;
const int sz = 500500;
int B[sz], dp[sz], gr, n, m;
vector<int> A[sz];
vector<int> res[sz];
queue<pair<int, int> > Q;
int next(int v) {
if (!B[v])
return v;
else
return dp[v] = next(dp[v]);
}
void bfs(int v) {
pair<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 int64_t MOD = 1e9 + 7;
int64_t n, m;
vector<int64_t> adj[500001];
vector<vector<int64_t> > ans;
vector<int64_t> candi;
set<int64_t> st;
void dfs(int64_t i) {
candi.push_back(i);
st.erase(i);
vector<int64_t> connect;
for (const int64_t &j : st) {
if (!binar... | 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;
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;
int N, M;
vector<int> edge[500005], ans[500005];
int pA;
struct UFS {
int fa[500005];
void init(int n) {
int i;
for (i = 0; i < n; i++) fa[i] = i;
}
int find(int x) { return x == fa[x] ? x : (fa[x] = find(fa[x])); }
void uni(int x, int y) { fa[find(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 long long N = 5e5 + 5;
unordered_set<long long> g[N], s;
vector<long long> component;
void dfs(long long node) {
component.push_back(node);
s.erase(node);
vector<long long> to_del;
for (auto it : s) {
if (g[node].find(it) == g[node].end()) {
to_del.p... | 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 {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Ta... | 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, x, K, y;
set<int> s;
set<pair<int, int> > a;
vector<int> ans[500005];
inline void dfs(int nod) {
set<int>::iterator it;
for (it = s.begin(); it != s.end();) {
if (!a.count(make_pair(min(*it, nod), max(*it, nod)))) {
int x = *it;
s.erase(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 N = 5e5 + 8;
int n, m, k, a, b, cnt;
vector<int> mark[N], nei[N], v;
set<int> s;
queue<int> q;
bool c[N];
void bfs(int u) {
q.push(u);
c[u] = 1;
mark[cnt].push_back(u);
s.erase(u);
while (!q.empty()) {
k = q.front();
for (int i = 0; i < nei[k].si... | 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 int64_t N = 5e5 + 1e1;
bool mark[N];
int64_t n, m, ans, par[N], sz[N];
vector<int64_t> mol[N], adj[N];
int64_t root(int64_t x) { return par[x] = (x == par[x] ? x : root(par[x])); }
int64_t mrg(int64_t x, int64_t y) {
x = root(x);
y = root(y);
if (x == y) {
r... | 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 MX5 = 5e5 + 10;
int n, m, ANS = 0, Ans[MX5], pointer = 0, P2 = 0, SZANS[MX5], u, v;
vector<int> G[MX5];
set<int> st;
bitset<MX5> mark;
void DFS(int u) {
st.erase(u);
mark[u] = 1;
Ans[pointer] = u;
pointer++;
ANS++;
std::set<int>::iterator itr = st.begi... | 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 visited[500010], n, m, mk[500010], pt[500010];
int mat[6010][6010];
vector<int> graph[500010], comp[500010], cur;
int nope = 0;
void dfs1(int s) {
visited[s] = 1;
cur.push_back(s);
for (int i = 1; i <= n; i++) {
if (i != s && !mat[s][i] && !visited[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 + 5;
vector<int> G[N];
int n, m, L[N], R[N];
bool vis[N];
queue<int> Q;
vector<int> cur;
vector<vector<int> > ans;
void Delete(int x) {
R[L[x]] = R[x];
L[R[x]] = L[x];
}
bool Find(int u, int v) {
vector<int>::iterator it = lower_bound(G[u].begin(), 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 | #include <bits/stdc++.h>
using namespace std;
pair<int, int> e[2 * 10 * 100001];
int h[5 * 100001], sv[2][5 * 100001], ret[5 * 100001], w[2], t, run, Left, top,
k, s[5 * 100001], u, v;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (long i = long(1); i <= long(m); i++)
scanf("%d%d", &e[i].first, &e[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;
struct _ {
_() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
stringstream ss;
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
o << "(" << t.first << ", " << t.second << ")";
return o;
}
template <class T>
inline string tost... | 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.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class E3 {
InputStrea... | 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 = 500 * 1000 + 10;
vector<int> adj[MAX_N], vec[MAX_N];
int n, m, cnt;
queue<int> q;
set<int> s;
void readInput() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[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 MAXN = 500100;
unordered_set<int> G[MAXN], s_;
vector<int> v;
int n, m, a, b;
void dfs(int s) {
v.push_back(s);
std::vector<int> cur;
for (auto c : s_) {
if (G[s].find(c) != G[s].end()) continue;
cur.push_back(c);
}
for (auto sd : cur) s_.erase(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 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, cnt, belong[N];
vector<int> g[N], ans[N];
int get(int x) { return belong[x] ? belong[x] = get(belong[x]) : x; }
void dfs(int i) {
ans[cnt].push_back(i);
belong[i] = i + 1;
for (int j = get(1), k = 0; j <= n; j = get(j + 1)) {
for (... | 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 + 1000;
int n, m, ans, par[MAXN];
vector<int> adj[MAXN], out[MAXN];
bool mark[MAXN];
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void dfs(int x) {
mark[x] = 1;
par[x] = x + 1;
for (int i = 0; i < adj[x].size... | 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;
class Unvis {
vector<int> next;
vector<bool> isVis;
public:
Unvis(int n) {
next = vector<int>(n + 1);
isVis = vector<bool>(n + 1, false);
iota(next.begin(), next.end(), 0);
}
int next_node(int u) {
return not isVis[u] ? u : next[u] = next_node(ne... | 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 + 7;
int n, m, u, v;
set<int> q;
vector<int> ans[maxn], g[maxn];
int tot;
int cnt, del[maxn];
void solve(int u) {
q.erase(u);
ans[++tot].push_back(u);
queue<int> qq;
qq.push(u);
while (!qq.empty()) {
int u = qq.front();
qq.pop();
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 | #include <bits/stdc++.h>
using namespace std;
set<int> st;
vector<int> mp[500600], ans[500600];
int del[500600];
int n, m, tot;
void Bfs(int x) {
ans[tot].push_back(x);
st.erase(x);
queue<int> s;
s.push(x);
while (!s.empty()) {
int u = s.front();
s.pop();
int cont = 0;
for (set<int>::iterator ... | 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];
map<int, bool> mp[M];
vector<int> ve[M], adj[M];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
adj[x].pu... | 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 = (int)1e6 + 123;
const long long INF = (long long)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
void megaRandom() {
unsigned int FOR;
asm("rdtsc" : "=A"(FOR));
srand(FOR);
}
int n, m;
vector<int> g[N];
int col;
bool u[N];
set<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 = 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 | 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 | 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 N = 5e5 + 5;
unordered_set<int> notInGraph[N];
set<int> notVis;
vector<int> cities;
void bfs(int i) {
notVis.erase(i);
queue<int> q;
q.push(i);
while (!q.empty()) {
int u = q.front();
q.pop();
cities.push_back(u);
vector<int> used;
for ... | 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;
int inf_int = 2e9;
long long inf_ll = 2e18;
const double pi = 3.1415926535898;
template <typename T, typename T1>
void prin(vector<pair<T, T1> >& a) {
for (int i = 0; i < a.size(); i++) {
cout << a[i].first << " " << a[i].second << "\n";
}
}
template <typename T, ty... | 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 maxn = 5e5 + 500;
vector<long long> ger[maxn];
long long moa[maxn];
long long n;
void okeyed(long long a) {
long long savea = a;
vector<long long> ham;
vector<long long> ham2;
vector<long long> tofale;
for (long long i = 0; i < ger[a].size(); 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;
int n, region, deg[500500], d[500500], r[500500], l[500500];
vector<int> ans[500500], D[500500], a[500500];
void remove(int x) {
l[r[x]] = l[x];
r[l[x]] = r[x];
}
int connect(int x, int y) {
if (deg[x] > deg[y]) swap(x, y);
if (!deg[x]) return 1;
return *(lower_bo... | 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 comment(linker, "/STACK:16000000")
using namespace std;
const long long MAXN = 10000000;
long long N, M, a, b;
vector<vector<int> > G, comp;
set<int> S;
int k = 0;
void dfs(int u) {
comp[k].push_back(u);
for (set<int>::iterator it = S.begin(); it != S.end();) {
int q = *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 N = 5e5 + 5;
vector<int> adj[N], ans[N], st;
bool mark[N];
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_back(u);
}
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>
const int MAXN = 500000;
int n, m;
std::set<std::pair<int, int>> G;
std::set<int> notVisitedYet;
std::vector<int> C[MAXN];
int component = 0;
void DFS(int node, std::set<int>::iterator& nodeIt) {
notVisitedYet.erase(nodeIt);
C[component].push_back(node);
auto it = notVisitedYet.begin();
... | 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 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m, i, x, y, j, ct;
int ata[N], S[N], S2[N], H[N];
vector<int> ans[N], V[N];
set<int> s;
int atabul(int x) { return x == ata[x] ? x : ata[x] = atabul(ata[x]); }
int main() {
scanf("%d %d", &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;
int n, k;
vector<int> v[int(6e5) + 5], w;
int vis[int(6e5) + 5];
set<int> s;
void dfs(int k) {
bool flag = 1;
if (s.find(k) != s.end()) {
s.erase(k);
w.push_back(k);
if (s.empty()) return;
}
for (auto const x : s) {
if (!binary_search(v[k].begin(), 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;
queue<int> q;
vector<int> gr[500020], er, ans[500020];
set<int> r;
int mark[500020];
int isval;
int f;
int x = 0;
int mm = 1;
void bfs(int v) {
while (!q.empty()) {
f = q.front();
q.pop();
for (auto i : r) {
isval = 0;
if (gr[f].size() == 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;
inline int read() {
int k = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
k = k * 10 + ch - '0';
ch = getchar();
}
return k * f;
}
inline void write(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 N = 5e5 + 5;
queue<int> q;
set<int> myset;
vector<int> g[N];
int n, m, cnt, c[N];
vector<int> e, C[N];
set<int>::iterator it;
bool bs(int v, int u) {
if (g[v].size() == 0) return true;
int up = g[v].size(), dw = 0;
while (up - dw > 1) {
int mid = (up + 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;
template <class T>
bool uin(T& a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
return a < b ? (a = b, true) : false;
}
struct dsu {
vector<int> p;
dsu(int n) : p(n, -1) {}
inline int size(int x) { return -p[get(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 | #include <bits/stdc++.h>
using namespace std;
int nxt[500004];
int find(int x) { return (x == nxt[x]) ? x : nxt[x] = find(nxt[x]); }
vector<int> sol[500004];
vector<int> cur;
vector<int> adj[500004];
int n;
int sz = 0;
void dfs(int x) {
nxt[x] = x + 1;
sol[sz].push_back(x);
int j = 0, omar = adj[x].size();
for ... | 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 MM = 5 * 100000;
const int N = 1e6;
vector<int> adj[N];
vector<int> ans[MM];
set<int> s;
int cnt, n, m;
queue<int> q;
bool mark[MM];
void bfs(int x) {
q.push(x);
s.erase(x);
mark[x] = true;
while (!q.empty()) {
ans[cnt].push_back(q.front());
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 | // 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>
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 500010;
struct DSU {
int par[MAXN];
int sz[MAXN];
DSU() {
for (int i = 1; i < MAXN; i++) par[i] = i;
for (int i = 1; i < MAXN; i++) sz[i] = 1;
}
int get(int x) {
if (par[x] == x) return x;
return par[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;
int n, m, moal[Maxn], cnt, numd, mark[Maxn];
vector<int> adj[Maxn], ans[Maxn];
bool markadj[Maxn];
void dfs(int v, int a) {
mark[v] = a;
int pt = 0;
for (int i = 0; i < n; i++) {
if (i != v) {
if (pt < (int)adj[v].size() && ... | 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 + 5;
vector<int> adj[N], ans[N], st;
int n, m, cnt;
bool mark[N];
int main() {
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_back(u);
}
for (int ... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.