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
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numCha...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& out, const vector<T>& v) { out << "["; for (const T& x : v) { out << v << ", "; } out << "]"; return out; } template <typename T, typename S> ostream& operator<<(ostream& out, const pair<T, S>& p) { out << "...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, k, u, v; int a[N], b[N]; set<int> s[N]; int main() { cin >> n >> k; for (int i = 1; i <= k; i++) { cin >> u >> v; s[u].insert(v); s[v].insert(u); } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; vector<vector<long long> > al(n, vector<long long>()); if (2 * m >= (n * (n - 1))) { cout << "NO" << endl; return 0; } vector<long long> deg(n, 0); for (int i = 0;...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y, a[100005], b[100005]; set<int> s[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; while (m--) { cin >> x >> y; s[x].insert(y); s[y].insert(x); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; void solve(int x, int y, int n) { vector<int> ans(n + 1); ans[x] = 1; ans[y] = 2; for (int i = 1, j = 3; i <= n; i++) { if (ans[i] == 0) { ans[i] = j++; } } for (int i = 1; i <= n; i++) { cout << ans[i] << ' '; } cout << '\n'; ans[y] = 1;...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 1e5 + 5; vector<...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; vector<set<int>> a; int main() { cin >> n >> m; a.resize(n); for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; a[x - 1].insert(y - 1); a[y - 1].insert(x - 1); } if (n == 1) { cout << "NO" << endl; return 0; } int minidx =...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const long long mod = 998244353; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-7; inline long long read() { long long X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; set<long long> adj[100003]; int a[100002]; int b[100002]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; adj[x].insert(y); adj[y].inse...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 6; int n, k, x, y; int a[maxn], b[maxn]; bool used[maxn]; vector<int> adj[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; if (n == 1 || n == 2) { if (n == 2 && k == 0) { cout << "YES\n1 2\n1 1\n"; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m, t1, t2, a[100005], b[100005]; unordered_set<long long> g[100005]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (long long i = 1; i <= m; ++i) { cin >> t1 >> t2; g[t1].insert(t2); g[t2].insert(t1); } for (lon...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; template <class T> using priority_queue_min = priority_queue<int, vector<int>, greater<int>>; struct greater1 { bool operator()(const long &a, const long &b) { return a > b; } }; long long MOD = 1e9 + 7; long long gcd(long long n1, long long n2) { if (n2 == 0) return n1...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, m, chk[100100], a[100100], b[100100]; vector<int> v[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; v[a].push_back(b), v[b].push_back(a); ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int int_inf = 0x3f3f3f3f; const long long int ll_inf = 0x3f3f3f3f3f3f3f3f; const int max_n = 1e5 + 5; int cnt[max_n]; int head[max_n], to[max_n << 1], nxt[max_n << 1]; int tot = 0; inline void add(int a, int b) { to[++tot] = b; nxt[tot] = head[a]; head[a] = tot;...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=1; while(T-->0) { int n=input.nextInt(); int m=input.nextInt();...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; void update(int i, int j) {} int main() { int n, m; cin >> n >> m; map<pair<int, int>, int> x; for (int i = 0; i < m; i++) { int x1, y1; cin >> x1 >> y1; if (x1 < y1) x[make_pair(x1, y1)] = 1; else x[make_pair(y1, x1)] = 1; } for (int...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; const long long mod = 1e9 + 7; const long long prost = 37; const long long N = 6e5 + 500; const int big = 1e9 + 1; const long long INF = 1e18 + 1; long long n, m, a[111111], b[111111]; set<long long> s[111111]; int main() { i...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1003; bool vis[N][N]; int dist[N][N]; char s[N][N]; int dy[4] = {1, 0, 0, -1}, dx[4] = {0, -1, 1, 0}; char g[4] = {'D', 'L', 'R', 'U'}; void solve() { set<pair<int, int> > s; int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { int x, y; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; int main() { int n, m, x, y, i, j, xx, yy, now; scanf("%d%d", &n, &m); if (m == (long long)n * (n - 1) / 2) { puts("NO"); return 0; } for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); mp[make_pair(x, y)] = 1; mp[mak...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; void cline() { cout << '\n'; } template <typename T, typename... V> void cline(T t, V... v) { cout << t; if (sizeof...(v)) cout << ' '; cline(v...); } void cspc() { cout << ' '; } template <typename T, typename... V> void cspc(T t, V... v) { cout << t; if (sizeof....
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int maxn = 1e5 + 5; int n, m, a = -1, b = -1; int ans[maxn]; vector<int> g[maxn]; int main() { scanf("%d%d", &n, &m); if (n == 1) { puts("NO"); return 0; } for (int i = (0); i < (m); ++i) { int u, v; scanf("%d%d", &u, &...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n, m; cin >> n >> m; vector<set<ll>> adj(n); vector<ll> a(n, -1); vector<ll> b(n, -1); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >>...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; inline void read(long long &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; x = flag ? -x : x; } inline void write(long long x...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> a[100003]; int cnt[100003], ans[100003]; vector<int> v[100003]; bool vis[100003]; int main() { cin >> n >> m; for (int i = 0; i < m; i++) cin >> a[i].first >> a[i].second, cnt[--a[i].first]++, cnt[--a[i].second]++, v[a[i].first].push...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; inline long long input() { long long n; cin >> n; return n; } long long pw(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * pw(a * a % md, b / 2, md) % md : pw(a * a % md, b / 2, md) % md)); } const long long...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
from sys import stdin rints = lambda: [int(x) for x in stdin.readline().split()] n, m = rints() if m == n * (n - 1) // 2: print('NO') exit() pair, ans, cur = set(), [0] * n, 0 for _ in range(m): u, v = rints() pair.add((u, v)) pair.add((v, u)) for i in range(1, n + 1): for j in range(i + 1, n...
PYTHON
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; int a[100006], x[100006], y[100006]; int r[100006]; bool used[100006]; int main(void) { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &x[i], &y[i]); r[x[i]]++; r[y[i]]++; } int k; for (k = 1; k <= n; k++) { if (r[k] ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; ifstream fin("input.txt"); ofstream fout("output.txt"); bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3; for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; } int NumDigits(int...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
//package rohspc2018; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Queue; import java.util.Set; public cl...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; set<pair<int, int>> s; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; s.insert({x, y}); s.insert({y, x}); } if (m >= n * (n - 1) / 2) return cout << "NO", 0; memset(a, -1, si...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector<pair<int, int>> a(m); vector<int> cnt(n); for (int i = 0; i < m; ++i) { cin >> a[i].first >> a[i].second; ++cnt[--a[i].first], ++cnt[--a[i].second]; } if...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
n, m= map(int, input().split()) s=set() for i in range(m): x,y=map(int, input().split()) s.add((x,y)) if m*2 == n*(n-1) or n<2 or n==2 and m==1: print('NO') exit() x, y = 0,0 for i in range(1,n+1): for j in range(i+1,n+1): if (i, j) not in s and (j, i) not in s: x=i ...
PYTHON3
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; map<int, int> Map[101000]; int n, m, A[101000], B[101000]; void Go(int a, int b) { int i; for (i = 1; i <= n; i++) { if (i <= a) { A[i] = B[i] = i; } else if (a < i && i < b) { A[i] = i + 1; B[i] = i; } else if (i == b) { A[i] = a + 1...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> v[200005]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } if (m == n * (n - 1) / 2) { cout << "NO\n"; return 0...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long int M = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int infi = LLONG_MAX; long long int ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, c, z, sum; set<long long int> v[M]; long long int a[M], b[M];...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> g[100005]; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } if (m == (n * ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.util.*; public class SolverD { StringTokenizer stok; BufferedReader br; PrintWriter pw; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { stok = new StringTokenizer(br.readLine()); } return stok.ne...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int read() { int nm = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0'; return nm * f; } bool vis[100010]; int be, ed, dft; vector<int> to[100010]; int n, m; int a[1...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long get(int q) { return (long long)q * 1ll * (q - 1) / 2; } map<pair<int, int>, int> exist; int ans[100005]; int main() { int n, m; scanf("%d %d", &n, &m); if (m == get(n)) { puts("NO"); return 0; } for (int i = 0; i < m; i++) { int x, y; sca...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> a[100010]; int ans[100010]; int main() { int n, m, x, y; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d%d", &x, &y); a[x].push_back(y); a[y].push_back(x); } if (n == 1) { printf("NO\n"); return 0; } x = -1; for...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n == 1) { cout << "NO\n"; return 0; } vector<set<int> > nums(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; nums[a].insert(b); nums[b].insert(a); } int one, two; on...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<vector<int> > ad(100005); int vis[100005]; int main() { int n, m, i, a, b, k, j; scanf("%d%d", &n, &m); while (m--) { scanf("%d%d", &a, &b); if (a > b) swap(a, b); ad[a].push_back(b); } a = 0; for (i = 1; i < n + 1; i++) { b = ad[i].size()...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MAX = 100010; int n, m; int u, v; int c; int a[MAX], b[MAX], bio[MAX]; vector<int> graf[MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> u >> v; graf[u].push_b...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 15; int n, m, a[N]; vector<int> g[N]; pair<int, int> get() { for (int i = 0; i < n; i++) { if (g[i].size() < n - 1) { set<int> s; for (int j : g[i]) s.insert(j); s.insert(i); for (int j = 0; j < n; j++) if (!s.count(...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m; int a[100005], b[100005]; vector<int> G[100005]; int main() { cin >> n >> m; if (n == 1) { puts("NO"); return 0; } if (n * (n - 1) / 2 <= m) { puts("NO"); return 0; } puts("YES"); for (int i = 1; i <= m; i++) { int a, b; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long double eps = 0.00000001; const long long MOD = 998244353; int32_t main() { ios_base::sync_with_stdio(NULL); srand(22); cout << fixed << setprecision(10); long long n, m; cin >> n >> m; vector<long long> c(n + 1, 0); c[0] ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> const int N = 1e5 + 5; int n, m, a[N], b[N]; std::unordered_set<int> g[N]; int main() { scanf("%d%d", &n, &m); for (int x, y, i = 1; i <= m; i++) { scanf("%d%d", &x, &y); if (x > y) std::swap(x, y); g[x].insert(y); g[y].insert(x); } for (int i = 1; i <= n; i++) { for...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using gr = vector<vll>; using wgr = vector<vpll>; struct d_ { template <typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *th...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = int(1e9); vector<set<int>> com; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, x, y; cin >> n >> m; com.resize(n + 1); for (int i = 0; i < m; i++) { cin >> x >> y; com[x].insert(y); com[y].inse...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int v[MAXN]; map<pair<int, int>, bool> viz; int main() { int p1 = -1, p2 = -1; int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { pair<int, int> x; cin >> x.first >> x.second; if (x.first > x.second) swap(x.first, x.second...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; set<int> s[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); while (m--) { int x, y; scanf("%d%d", &x, &y); if (x > y) swap(x, y); s[x].insert(y); } int cnt; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 101010; int n, m, a[N], b[N]; vector<int> g[N]; int main(void) { scanf("%d%d", &n, &m); for (int i = 1, x, y; i <= m; i++) { scanf("%d%d", &x, &y); if (x > y) { swap(x, y); } g[y].push_back(x); } for (int i = 1; i <= n; i++) { ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
// practice with kaiboy import java.io.*; import java.util.*; public class CF1090D extends PrintWriter { CF1090D() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1090D o = new CF1090D(); o.main(); o.flush(); } void main() { int n = sc.nextInt(); int m = ...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> const int MAXINT = 2147483640; const long long MAXLL = 9223372036854775800LL; const long long MAXN = 1e6; const double eps = 1e-9; const long long mod = 1e9 + 7; using namespace std; long long b[MAXN], a[MAXN]; set<long long> v[MAXN]; long long n, m; int main() { srand(time(0)); ios_base::s...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; set<pair<int, int> > st; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); st.insert({a - 1, b - 1}); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; if (x > y) { swap(x, y); } mp[make_pair(x, y)] = 1; } if (n == 1) { cout << "NO"; return 0; } int m1 = ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 1, mod = 1000000007; vector<long long int> adj[N]; signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long int pro = 1, temp, t, n, i, m, k, j, l, r, mid, x, y, z, rem, carry = 0, ind, ans ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1123456; const int MAXINT = 2147483098; const long long MAXLL = 9223372036854775258LL; int a[MAXN], b[MAXN]; bool used[MAXN]; vector<int> g[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int pos = 1; for (...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; if (n <= 450 and m == n * (n - 1) / 2) { cout << "NO\n"; return 0; } vector<set<int>> g(n + 1); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = (int)4e5 + 10; const int mod = (int)1e9 + 7; const int inf = (1 << 30) - 1; int n, m; set<int> s[maxn]; void solve() { cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; s[x].insert(y); s[y].insert(x); } for (int i...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; bool used[1000000]; map<pair<int, int>, int> mp; int val[1000000]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < k; i++) { int a, b; cin >> a >> b; mp[make_pair(a, b)] = 1; mp[make_pair(b, a)] = 1; } bool fl = false; int pos1 = 0; i...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.util.*; public class tr2 { static PrintWriter out; static StringBuilder sb; static long inf = (long) 1e10; static ArrayList<Integer> primes; static int[] si; static long mod = (long) 998244353; static long num = (long) 1e9 + 7; static long[][] memo; static int n; static long k; ...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int N, M; int tam[200005], ans[200005]; map<pair<int, int>, bool> ex; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N >> M; for (int m = 0; m < M; m++) { int u, v; cin >> u >> v; tam[u]++; tam[v]++; ex[{u, v}] = 1; ex[{v, u}] ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
from sys import stdin import operator as op from bisect import * from itertools import chain, repeat, starmap from functools import reduce class SortedList(): """Sorted list is a sorted mutable sequence.""" DEFAULT_LOAD_FACTOR = 500 def __init__(self, iterable=None): """Initialize sorted list ins...
PYTHON
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SimilarArrays { private static int n,m; private static int[][] arr; private static int[][] pairs; private static byte[] presence; private static int adjust=0; private static int[] arr2; private static int...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; set<pair<int, int>> st; for (int i = 0; i < M; i++) { int a, b; scanf("%d %d", &a, &b); if (a > b) swap(a, b); st.insert({a, b}); } int ans[100001][2]; for (int i = 1; i <= N; i++) { for (int j = i + 1;...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int N, M; int F[MAXN]; map<pair<int, int>, int> H; int A[MAXN]; int B[MAXN]; void rev(int st, int en) { if (st > en) return; vector<int> lol; for (int i = st; i <= en; ++i) lol.push_back(A[i]); reverse(lol.begin(), lol.end()); int cnt = 0;...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.util.ArrayList; import java.util.HashSet; import java.util.StringTokenizer; public class Task { public static void main(String[] args) throws IOException { new Task().go(); } PrintWriter out; Reader in; BufferedReader br; Task() throws IOException { ...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; int vis[100005]; 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); v[x].push_back(y); v[y].push_back(x); } int ans = n * (n - 1) / 2; if (n == 1 || n == 0) prin...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 5; const long long INF = 2e18; long long n, m, a[MAXN], b[MAXN], ans[MAXN], vis[MAXN], cnt = 1; pair<long long, long long> p[MAXN]; long long num; set<long long> s; long long du[MAXN]; vector<long long> e[MAXN], G[MAXN]; priority_queue<long long...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<long long> adj[100100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; if (n == 1) { cout << "NO"; return 0; } long long a[k + 100], b[k + 100]; long long arr1[n + 100]; long long arr2[n + 100]; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, m, i, j, z; pair<long long, long long> temp; cin >> n >> m; if (n == 1) cout << "NO"; else if (m == (n * (n - 1)) / 2) cout << "NO"; else { cout << "YES" << endl; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> myMap; int main(void) { int N, M; cin >> N >> M; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; myMap[make_pair(a, b)] = 1; myMap[make_pair(b, a)] = 1; } if (N < 1000 && M + M >= N * (N - 1)) { cout << "NO" << e...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long MAX = (long long)2e6 + 100; long long inf = (long long)1e18; long long mod = (long long)1e13 + 2987429; long long n, m, ans[MAX], b[MAX]; set<long long> gr[MAX]; void solve() { cin >> n >> m; for (int i = 0; i < m; i++) { ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; bool res = false; pair<int, int> equal = {-1, -1}; if (n > 1) { set<pair<int, int> > pairs; for (int i = int(0); i < int(m); i++) { int a, b; cin >> a >> b; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; const int INF = INT_MAX; const long long INFLL = (long long)1e18; const double PI = acos(-1.0); template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gc...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long A = 911382325, B = 972663749, M = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, g, j, w, l, r, t, v, m, k, x, y, x1, y1, z1, l1, r1, maxi, mini, sum, q, p; cin >> n; cin >> m; vector<pair<long long, long long> ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, a[100009]; map<pair<int, int>, int> mp; int main() { scanf("%d%d", &n, &m); if (m == (long long)n * (n - 1) / 2) { puts("NO"); return 0; } int i, j, x, y; for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); if (x > y) swap(x, y); mp[mak...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWri...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; bool cmp(array<long long, 2> x, array<long long, 2> y) { return x[0] < y[0]; } map<pair<long long, long long>, bool> mp; long long n; void solve() { long long m; cin >> n >> m; long long tt = m; bool flag = 1; if (m == n * (n - 1) / 2) { flag = 0; } while ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.util.*; public class Solution{ InputStream is; static PrintWriter out; String INPUT = ""; static long mod = (long)1e9+7L; public void solve(){ int n = ni(), m = ni(); int[][] inp = new int[m][2]; ArrayList<Integer>[] adj = new ArrayList[n+1]; for(int i = 0; i <= n; i++){ ...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); long long n, m; cin >> n >> m; vector<vector<int>> a(n + 1); vector<int> b(n + 1); for (int i = 0, u, v; i < m; ++i) { cin >> u >> v; a[u].push_back(v); a[v].p...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m, t1, t2, a[100005], b[100005]; set<long long> g[100005]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (long long i = 1; i <= m; ++i) { cin >> t1 >> t2; g[t1].insert(t2); g[t2].insert(t1); } for (long long i =...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, inf = 1e9 + 7, mod = 1e9 + 7; const long double eps = 1e-12; const long long linf = (long long)1e18 + 7; long long n, m, x, y, a[N], b[N], cnt; vector<long long> g[N]; map<int, bool> q; bool ok = 0; int main() { cin >> n >> m; for (int i = 1; i <=...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; set<pair<int, int> > edges; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; if (a > b) swap(a, b); edges.emplace(a, b); } int nd1 = -1, nd2 = -1; for (int...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long INF64 = 1e18 + 1337; const int INF32 = 1e9 + 228; const int MOD = 1e9 + 7; int n, m; vector<set<int> > g; int x[100001], y[100001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; g.resize(n); for (int i = 0; i ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.awt.*; import java.util.*; public class SimilarArrays { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int M = scanner.nextInt(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long power(long long x, long long y) { if (y == 0) return 1; if (y == 1) return x; if (y % 2) return x * power(x, y / 2) * power(x, y / 2); else return power(x, y / 2) * power(x, y / 2); } void solve() { long long n, m, x, y; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using std::cin; using std::cout; long long MOD = 998244353; int main() { int n, m; cin >> n >> m; vector<int> arr[n + 1]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; arr[a].push_back(b); arr[b].push_back(a); } if (m == n * (n - 1) / 2)...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; long long MOD = 998244353; long long mpow(long long a, long long b) { if (b >= (MOD - 1)) b %= (MOD - 1); if (b == 0) return 1; long long t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) t1 *= a; t1 %= MOD; return t1; } long l...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int du[N]; vector<int> G[N]; bool vis[N]; int main() { memset(vis, 0, sizeof(vis)); int n, m; cin >> n >> m; int u, v; for (int i = (1); i < (m + 1); i++) { cin >> u >> v; if (u > v) swap(u, v); G[u].push_back(v); G[v].push_b...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int A[100001], B[100001]; vector<int> compared_with[100001]; bool finder[100001]; int main() { int n, m, i, a, b, mark; scanf("%d%d", &n, &m); if (m >= (n - 1) * 1LL * n / 2) printf("NO"); else { memset(A, 0, sizeof A); memset(B, 0, sizeof B); for (i...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, a[100010], b[100010], n1, n2; bool mk[100010]; vector<int> g[100010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.setf(ios::fixed); cout.precision(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> namespace { using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } } // namespace set<long long> st[100100]; int main() { long long n, m, a, b, pk = 0; cin >> n >> m; long long m1[n + 1], m2[n + 1], ar[n + 1]; memset(m...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const int inf = (int)1e9 + 7; const double eps = 1e-7; const double pi = 3.14159265359; const int N = (int)1e5; int n, m, tin[N], timer; vector<int> adj_list[N]; void dfs(int v, int p = -1) { if (tin[v]) return; tin[v] = ++timer...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = 3.1415926535897932384626; const double eln = 2.718284590452353602874; const int maxn = 100005; vector<int> g[maxn]; int n, m, ans[maxn]; bool t[maxn]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int x...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const bool ready = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); const double PI = acos(-1); using ll = long long; using pii = pair<ll, ll>; using pdd = pair<double, double>; using vd = vector<double>; usin...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; int n, m; int deg[100005]; vector<int> G[100005]; int ans[100005]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); deg[u]++; deg[v]++; G[u].push_back(v); G[v].push_back(u)...
CPP