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
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> const long double eps = 1e-8; const long double pi = acos(-1); using namespace std; char temp[2000005]; int ar[] = {0, 0, -1, 1, 1, 1, -1, -1}; int ac[] = {-1, 1, 0, 0, 1, -1, -1, 1}; vector<vector<int>> undir_adj, dir_adj; int col[2000005], a[2000005], use[2000005]; bool vis[2000005], cycle[20...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-11; vector<vector<int> > g, gr; vector<int> num, inComponent; bitset<(int)1e5 + 5> us; void dfs(int v, vector<int>& order) { us[v] = true; for (int i = 0; i < (int)g[v].size(); i++) if (!us[g[v][i]]) dfs(g[v][i], order); order.push_back(...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Stack; import java.util.StringTokenizer; public class Main { static int N, counter, SCC; static ArrayList<Integer>[...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 105000; int n, m; int tin[MAXN], tout[MAXN]; vector<int> g[MAXN]; vector<int> gr[MAXN]; vector<int> gg[MAXN]; vector<int> vv; bool used[MAXN]; int sz[MAXN]; int cursize; int p[MAXN]; bool has[MAXN]; int ans; void dfs(int v) { used[v] = true; for (int i ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int f[100005], ans[100005], vis[100005], cyc[100005], siz[100005]; vector<int> e[100005]; int find(int x) { if (f[x] == x) return x; return f[x] = find(f[x]); } void uni(int x, int y) { if (find(x) == find(y)) return; siz[find(y)] += siz[find(x)]; f[find(x)] = fin...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Bit...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> G[100000]; vector<int> undirected_G[100000]; bool vis[100000], undirected_vis[100000]; vector<int> vs; vector<vector<int> > scc; int n, m, counter, u, v, sum; void dfs(int u) { undirected_vis[u] = true; vs.push_back(u); for (int i = 0; i < undirected_G[u]....
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(), m = s.nextInt(); int[] f = new int[n], count = new int[n], min = new int[n]; Vertex[] vs = new Vertex[n]; for (int i = 0; i < n; i++) { ...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.*; import java.math.*; import java.util.*; public class SolutionB { public static void main(String[] args) { new SolutionB().run(); } int n; int m; ArrayList<Integer> arr[], arr2[], arrx; int col[]; boolean flag; void dfs(int v){ col[v] = 1; arrx.add(v); for(int t:arr2[v]){ if(col[t...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; int tin[N], low[N], tim; int comp[N], cmp; int sz[N], par[N], szp[N]; bool onStack[N]; stack<int> st; vector<int> g[N]; void dfs(int u) { tin[u] = low[u] = ++tim; st.emplace(u); onStack[u] = true; for (auto v : g[u]) { if (tin[v]...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; bool vis[100010]; set<int> st; vector<int> cic; vector<int> pset; int cant = 0; void init(int c) { cant = c; pset.resize(c); iota(pset.begin(), pset.end(), 0); } int findset(int a) { if (pset[a] == a) return a; return pset[a] = findset(pset...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } struct UnionFind { vector<int> data; void init(int n) { data.assign(n, -1); } bool unionSet(int ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; list<int> adj[100007], drc[100007]; int N; int p[100007], v[100007], visited[100007]; bool go2(int u) { visited[u] = 1; list<int>::iterator it; for (it = drc[u].begin(); it != drc[u].end(); it++) { if (visited[*it] == 1) return 1; if (!visited[*it] && go2(*it)...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.util.Arrays; import java.util.InputMismatchException; import java.util.ArrayList; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void ...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; const int mod = (int)1e9 + 7; const int logN = 18; const int inf = 1e9; const int N = 1e5 + 5; const int M = 2050; int root[N], n, m, k, h[N], x, y, ans, col[N]; vector<int> v[N]; int findset(int x) { return root[x] = x == root[x] ? x : find...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; bool used[maxn]; vector<int> vs; vector<int> g[maxn], rg[maxn]; int cmp[maxn], cmpsize[maxn]; int n, m, x, y; void dfs(int pos) { used[pos] = true; for (int i = 0; i != g[pos].size(); i++) if (!used[g[pos][i]]) dfs(g[pos][i]); vs.push...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > e, ne; int n, m; int dfn[500000], low[500000], TIME, START; int c, belong[500000], ins[500000]; stack<int> dfsn; void Tarjan(int v) { dfsn.push(v); ins[v] = 1; dfn[v] = low[v] = ++TIME; for (int i = 0; i < e[v].size(); i++) { if (dfn[e[v][i]...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.File; import java.util.ArrayList; import java.io.FilterInputS...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> in[2 * 100000 + 5], out[2 * 100000 + 5]; bool cycle; int visited[100000 + 5]; int done[100000 + 5]; int offset = 1; void dfs(int v) { visited[v] = offset; for (int i = 0; i < out[v].size(); ++i) { int u = out[v][i]; if (visited[u] == 0) { dfs(u...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, cc, num[100015], dfsCnt, res; vector<int> a[100015], adj[100015], c[100015]; bool vis[100015]; void dfs(int u) { vis[u] = true; c[cc].push_back(u); for (int v : adj[u]) if (!vis[v]) dfs(v); } bool check(int u) { bool res = true; num[u] = ++dfsCnt; ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > G, G2, U; vector<bool> vis; vector<int> v; void dfs1(int nodo) { vis[nodo] = 1; for (auto it : G[nodo]) { if (!vis[it]) { dfs1(it); } } v.push_back(nodo); } vector<int> sz; vector<int> grupie; int aux = 0; bool sipapi; int hijos = ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, m, s, grp = 0, check = 0, vertices = 0, ans = 0; vector<long long> g[N], undirG[N], rg[N], todo; long long comp[N], sizecomp[N]; bool vis[N], checkSCC[N]; vector<long long> mark[N]; void dfs(long long k) { vis[k] = 1; for (auto ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
def main(): n, m = map(int, input().split()) n += 1 cluster, dest, ab = list(range(n)), [0] * n, [[] for _ in range(n)] def root(x): if x != cluster[x]: cluster[x] = x = root(cluster[x]) return x for _ in range(m): a, b = map(int, input().split()) ab[a]....
PYTHON3
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5; const int INF = 0x3f3f3f3f; struct Edge { int v, nxt, sign; } E[MX]; int Head[MX], rear; void edge_init() { rear = 0; memset(Head, -1, sizeof(Head)); } void edge_add(int u, int v, int s) { E[rear].v = v; E[rear].nxt = Head[u]; E[rear].sig...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int INF = (-1u) / 2; const long long int INF2 = (-1ull) / 2; int a, b, i, d, us[1011000], j, k, n, m, timer = 0, l, r, x, y, par[200020], siz[200010], us2[100020]; int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0; ve...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> v[101010]; vector<int> x[101010]; int k[101010]; int e[101010]; int c = 1; bool b[101010]; void dfs(int i) { if (e[i]) return; e[i] = c; for (int j : x[i]) dfs(j); } bool haku(int s) { if (k[s] == 2) return false; if (k[s] == 1) { return ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Map.Entry; import java.util.Stack; public class B { FastScanner in = n...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct dsu_ele { int par, rankt; bool cir; } dsu[200009]; vector<int> st, g[200009]; bool ok[200009], done[200009]; int n, m, u, v, i, j, low[200009], disc[200009], nodeval[200009], scc, res, cnt, nodecnt[200009]; int getpar(int x) { ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m, ans, c[N], ctot, ind[N], q[N], ql, qr; int head[N], nxt[N], to[N], cnt = 1; vector<int> wcc[N], g[N]; void add(int u, int v) { nxt[++cnt] = head[u]; head[u] = cnt; to[cnt] = v; } void findwcc(int u) { wcc[c[u]].push_back(u); for (au...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, num, dfsn, K, ans, sum[300005], low[300005], dfn[300005], st[300005], top, head[300005], x[300005], y[300005], bl[300005], tt, h[300005]; bool inq[300005], vis[300005]; struct edge { int to, next; } g[300005]; void tj(int u) { dfn[u] = low[u] = ++dfsn; i...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1}; const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1}; const double pi = acos(-1.0); const int N = 1e5 + 100; int n, m, rudu[N], ans; vector<int> G[N], G1[N], v; queue<int> dl; bool vis[N]; void dfs(int x) { if (vis[x]) return;...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> int e[2][100010LL], star[100010LL] = {0}, tote = 0; inline void AddEdge(int u, int v) { tote++, e[0][tote] = v, e[1][tote] = star[u], star[u] = tote; } int fa[100010LL] = {0}; inline int GetAnc(int u) { return fa[u] ? fa[u] = GetAnc(fa[u]) : u; } inline void Union(int u, int v) { u = GetAnc...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int inf = 1e9 + 10; int n, m, sz(0); vector<int> G[maxn], H[maxn]; bool marked[maxn]; int visited[maxn], p[maxn], temp[maxn]; void dfs(int src, int v) { p[v] = src; sz++; marked[v] = true; for (int b : G[v]) { if (marked[b]) cont...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> edges[100000], sets[100000]; int belongs[100000]; bool v[100000], st[100000], cyc[100000]; void dfs(int n) { if (st[n]) cyc[belongs[n]] = true; if (v[n]) return; v[n] = st[n] = 1; for (int i = int(0); i < int(edges[n].size()); i++) { dfs(edges[n][i])...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> ugrph[110000], dgrph[110000]; int comp[110000], low[110000], disc[110000], n, m, cm, tme = 1; bool hascycle[110000], visited[110000], instack[110000]; stack<int> stk; void dfs(int node, int c) { visited[node] = 1; comp[node] = c; for (int i = 0; i < ugrph[...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int in[100005], dfn[100005], low[100005], s[100005], cnt, p, top, be[100005], cn[100005], f[100005]; void tarjan(int u) { dfn[u] = low[u] = ++cnt; s[++top] = u; in[u] = 1; for (int i = 0; i < g[u].size(); i++) { int j = g[u][i]; if...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int N = 101000; int n, m, cnt[N], comp[N], a[N], b[N], cur, k, l, ans, ans1; vector<int> g[N], gc[N], gt[N], order; bool used[N]; void dfs(int v) { used[v] = true; for (int i = 0; i < gt[v].size(); i++) if (!used[gt[v][i]]) dfs(gt[v...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; vector<int> adj[MAX], adj2[MAX]; int usd[MAX]; bool ciclo; vector<vector<int> > comp; vector<int> componente; void dfs(int u) { usd[u] = 1; componente.push_back(u); for (int i = (0); i < (adj[u].size()); i++) { int v = adj[u][i]; if (!...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int const maxsize = 100100; int n, m; vector<int> unedge[maxsize], edge[maxsize]; vector<int> tem; bool vis1[maxsize]; int vis2[maxsize]; int flag; void dfs1(int u) { vis1[u] = 1; tem.push_back(u); for (int i = 0; i < unedge[u].size(); i++) if (!vis1[unedge[u][i]]...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> E[100001]; vector<int> G[100001]; int n, m, co = 1, res; int vis[100001], col[100001], cnt[100001], ans[100001]; void dfs1(int x, int c) { col[x] = c; cnt[c]++; for (int i = 0; i < E[x].size(); i++) if (!col[E[x][i]]) dfs1(E[x][i], c); } void dfs2(int ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, ans, l, r, x, y; int Q[100100]; int tot[100100]; int fa[100100]; bool vis[100100]; bool flg[100100]; vector<int> v[100100]; int Fd(int m) { if (fa[m] != m) fa[m] = Fd(fa[m]); return fa[m]; } int main() { memset(flg, 0, sizeof flg); cin >> n >> m; for (in...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int limN = 1e5 + 5; struct Nodo { Nodo* padr = NULL; int cnt = 1; int id; Nodo(int id) : id(id) {} Nodo* raiz() { Nodo* pos = this; while (pos->padr) pos = pos->padr; return pos; } void une(Nodo* B) { Nodo* A = this->raiz(); B = B->ra...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Stack; import java.util.ArrayList; impor...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int ans, n, m, x, y, i, cur_col, color[100100], v_col[100100], j, v, qb, qe, cur, mn, num, ans2, num2; vector<int> edge[100100], back[100100], order, n_edge[100100], n_edge_b[100100]; bool used[100100], used2[100100]; void dfs1(int v) { used[v] = true; for (int i = ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; int n, m, ans, dor[maxn], tmp; bool mark[maxn], flag; vector<int> e[maxn], e_rev[maxn]; void dfs(int v) { mark[v] = 1; e[0].push_back(v); tmp++; for (auto u : e[v]) { if (mark[u] == 0) { dfs(u); } } for (auto u : e_rev[v])...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; int a, b; vector<int> undiradj[100001]; vector<int> diradj[100001]; vector<int> dirjda[100001]; stack<int> s; bool vis[100001]; vector<int> scc[100001]; bool isinscc[100001]; bool hascycle; void dfs(int node) { if (!vis[node]) { vis[node] = true; for (in...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> int n, m, cnt, head[100100], fa[100100], sccno[100100], lowlink[100100], pre[100100]; int stack[100100], top, scc_cnt, dfs_clock, size[100100], vis[100100], ans; struct data { int to, next; } edge[100100]; inline void Add_Edge(int u, int v) { edge[++cnt] = (data){v, head[u]}; head[u] ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 100007; struct eT { void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; } int u, v, last; } edge[M...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> graph[100001]; int parent[100001], vis[100001], cnt[100001]; int rep(int a) { if (parent[a] == a) return a; else return parent[a] = rep(parent[a]); } void dfs(int n) { vis[n] = 2; for (auto v : graph[n]) { if (vis[v] == 0) dfs(v); if (vis...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> v[maxn]; vector<int> v_[maxn]; vector<int> tp; bool flag[maxn]; int mark[maxn], con[maxn]; inline void dfs1(int x) { flag[x] = true; for (int i = 0; i < v[x].size(); i++) if (flag[v[x][i]] == 0) dfs1(v[x][i]); tp.push_back(x)...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
//package codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.uti...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; int n, m, t, ans; vector<int> vec, topo, G[MAXN], G1[MAXN]; bool mark[MAXN], mark1[MAXN], mark2[MAXN]; void dfs2(int v) { mark1[v] = true; for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; if (!mark1[u]) dfs2(u); } for (int i ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)(1e5) + 10; struct DSU { int father[MAX_N]; DSU() {} DSU(int n) { for (int i = 0; i < n; i++) { father[i] = i; } } int find(int a) { int ret = a; while (father[ret] != ret) ret = father[ret]; while (father[a] != a) ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; vector<int> g[N], rg[N], newG[N], tin(N), tout(N), used(N), ord, comp(N), cnt(N); int cc = 0; void dfs1(int v) { used[v] = 1; for (auto u : g[v]) { if (!used[u]) dfs1(u); } ord.push_back(v); } void dfs2(int v) { used[v] = 1; comp...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long maxn = 200005; vector<long long> adj[maxn]; long long color[maxn]; bool cycle = false; void dfs(long long u) { color[u] = 1; for (long long v : adj[u]) { if (color[v] == 1) cycle = true; else if (color[v] == 0) dfs(v); } color[u] ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> g[213700]; vector<int> gT[213700]; vector<int> g2[213700]; bool vis1[213700]; int kol = 1; int num[213700]; int revnum[213700]; void dfs1(int a) { vis1[a] = true; for (int i = 0; i < g[a].size(); i++) { if (!vis1[g[a][i]]) { dfs1(g[a][i]); } ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int const Max = 2e5 + 10; bool mark[Max]; int col[Max]; int ans = 0, mo = 0, cnt = 0; bool flag = 0; int sv[Max]; vector<int> adj[Max], adj2[Max]; vector<int> st; vector<int> ne[Max]; void dfs(int v) { mark[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = a...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> v[N], v1[N], v2[N]; bitset<N> B; int n, m, tmp1, tmp2, ans, i; struct M { vector<int> vr, t; int ss = 0; bitset<N> BM; bool b = 0, f = 0; void DFS(int u) { B[u] = 1; vr.push_back(u); for (auto x : v[u]) if (!B[x...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5; const long long mod = 1e9 + 7; const long double PI = 4 * atan((long double)1); long long pw(long long a, long long b) { return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mo...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > G; vector<vector<int> > G2; vector<int> mark1; vector<int> mark2; vector<int> a; void dfs1(int v) { if (mark1[v]) { return; } mark1[v] = 1; a.push_back(v); for (auto u : G2[v]) { dfs1(u); } } int dfs2(int v) { if (mark2[v]) { r...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; inline int in() { int x = 0; bool f = 0; char c; for (; (c = getchar()) < '0' || c > '9'; f = c == '-') ; for (x = c - '0'; (c = getchar()) >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0') ; return f ? -x : x; } struct edge { int to, nxt; ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int high[MAXN], num[MAXN], comp[MAXN], comp_num, dfs_num, cnt[MAXN]; bool mark[MAXN]; vector<int> v[MAXN], g[MAXN], s; void DFS(int n) { num[n] = dfs_num--; s.push_back(n); high[n] = num[n]; for (int i = 0; i < v[n].size(); i++) { int x ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; struct edge { int v, next; } e[100005]; int etot = 0; int g[100005]; void ae(int u, int v) { e[etot].v = v; e[etot].next = g[u]; g[u] = etot++; } int id[100005] = {0}; int dfn[100005] = {0}, low[100005] = {0}; int stk[100005], inst[100005] = {0}, top = 0; ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; struct UF { int n; vector<int> p; UF(int _n) : n(_n), p(n, -1) {} int group(int a) { if (p[a] == -1) return a; return p[a] = group(p[a]); } void merge(int a, int b) { int x = group(a), y = group(b); if (x == y) return; p[x] = y; } }; const ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> gr[114514], rgr[114514]; vector<int> vs; bool sumi[114514]; int cmp[114514], num[114514]; void dfs(int v) { sumi[v] = true; for (int i = 0; i < gr[v].size(); i++) { if (!sumi[gr[v][i]]) dfs(gr[v][i]); } vs.push_back(v); } void rdfs(int v, int k) { ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, m, broj_komponenti, odvojene, rj; int bio[MAXN], moja[MAXN], koliko[MAXN], ima[MAXN]; vector<int> graf[MAXN], obrnuti[MAXN], komponente[MAXN], graf_komponenti[MAXN]; stack<int> s; void dfs1(int x) { if (bio[x]) return; bio[x] = 1; for (...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, a, b, scc_size[500005], ans; int V; const int MAX_V = 500005; vector<int> G[MAX_V]; vector<int> rG[MAX_V]; vector<int> vs; bool used[MAX_V]; int cmp[MAX_V]; void add_edge(int from, int to) { G[from].push_back(to); rG[to].push_back(from); } void dfs(int v) { ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
//package e_contest_4; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Stack; import java.util.StringTokenizer; public class MrKitayutasTechnology { static ArrayList<Integer>...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> int ufp[100001]; int c; int getR(int x) { return ufp[x] == x ? x : (ufp[x] = getR(ufp[x])); } void uni(int a, int b) { a = getR(a); b = getR(b); if (a != b) { c++; ufp[a] = b; } } std::vector<int> map[100001]; int v[100001]; bool hC[100001]; int dfs(int x) { v[x] = 1; for (a...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") using namespace std; const int inf = (int)1e9 + 7; const long double eps = 1e-18; const int M = 1962; const int N = 100005; const int P = 137; const int K = 11; vector<int> g[N], gr[N]; bool u[N], ub[N], uu[N]; vector<int> comp; void dfs(int v) { u...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N(111111); vector<int> edges[N]; bool f[N]; int vst[N], rela[N]; int getr(int x) { int p(x), p1, p2; while (p != rela[p]) { p = rela[p]; } p1 = p; p = x; while (p != rela[p]) { p2 = rela[p]; rela[p] = p1; p = p2; } return p1; } vect...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> int N, M; std::vector<int> e[100005]; int p[100005]; bool cycle[100005]; bool seen[100005]; bool par[100005]; int ans; int find(int a) { if (p[a] == a) return a; else return p[a] = find(p[a]); } void join(int a, int b) { cycle[find(b)] |= cycle[find(a)]; p[find(a)] = find(b); } ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
def main(): n, m = map(int, input().split()) n += 1 cluster, dest, avail, ab = list(range(n)), [0] * n, [True] * n, [[] for _ in range(n)] def getroot(x): while x != cluster[x]: x = cluster[x] return x def setroot(x, r): if r < x != cluster[x]: setro...
PYTHON3
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int max_n = 111111, inf = 1111111111; int n, m, used[max_n]; vector<int> g[max_n], rg[max_n], comp; void dfs(int v) { used[v] = 1; comp.push_back(v); for (int i = 0; i < g[v].size(); ++i) { if (used[g[v][i]] == 0) { dfs(g[v][i]); } } for (int i...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > E, R; vector<int> col, TA; void dfs1(int u) { col[u] = 1; for (int i = 0; i < E[u].size(); i++) if (!col[E[u][i]]) dfs1(E[u][i]); TA.push_back(u); return; } void dfs2(int u, int t) { col[u] = t; for (int i = 0; i < R[u].size(); i++) ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; vector<int> g[MAXN]; vector<int> g2[MAXN]; int used[MAXN]; int color[MAXN]; int used2[MAXN]; vector<int> comp; int was; void dfs(int v, int cl) { used[v] = 1; color[v] = cl; comp.push_back(v); int sz, to; sz = g[v].size(); for (int i = ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> in[100001], out[100001]; int indeg[100001]; bool vis[100001]; int sp[100001]; bool spv[100001]; void dfs(int v) { if (vis[v]) return; vis[v] = 1; for (int u : out[v]) { sp[u] = sp[v]; dfs(u); } for (int u : in[v]) { sp[u] = sp[v]; dfs(u...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const double eps = 1e-7; const int maxn = 101000; const long long mod = 2000000011; vector<int> g[maxn], gr[maxn], gu[maxn]; vector<bool> used; vector<int> o; void dfs(int u) { used[u] = true; for (int i = 0; i < (int)g[u].size(); ++i) { if (!us...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; class graf { public: graf(int n) { this->n = n; vecini.resize(n + 1); viz.resize(n + 1); } void AddEdge(int x, int y) { vecini[x].push_back(y); vecini[y].push_back(x); } void GetComp(vector<vector<int> > &ret) { fill(viz.begin(), viz.end()...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, low[100005], num[100005], SCC[100005], DFScount; vector<int> ke[100005]; int SCCcount, nodeCount[100005], WCCnodeCount, ans; vector<int> SCCke[100005]; bool onenode; bool avail[100005]; stack<int> s; void DFS(int u) { ++DFScount; s.push(u); num[u] = DFScount...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; int pai[MAXN], g[MAXN], t[MAXN]; queue<int> fila[MAXN]; vector<int> grafo[MAXN]; int find(int x) { if (pai[x] == x) return x; return pai[x] = find(pai[x]); } void join(int a, int b) { pai[find(a)] = find(b); } bool vis[MAXN]; int main() { mems...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3228; int color[N], used[N], lol[N], heh[N], n, m, x, y, pep, ans; vector<int> v[N], v1[N]; void dfs(int x, int c) { color[x] = c; heh[c]++; for (int i = 0; i < v[x].size(); i++) { int to = v[x][i]; if (color[to] == 0) dfs(to, c); } for...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000000") using namespace std; int m; int n, low_link[100101], _index[100101], ind, group, gr[100101], sz[100101]; stack<int> st; vector<int> adj[100101]; bool instack[100101], vis[100101]; void tarjan(int c) { _index[c] = low_link[c] = ind++; instack...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5; vector<int> adj[MAX + 1], rev_adj[MAX + 1], undirected[MAX + 1]; vector<bool> visited(MAX + 1, -1); vector<vector<int> > dif_topo, scc, sub_graph; void dfs(int u) { visited[u] = 1; sub_graph.back().push_back(u); for (auto v : undirected[u]) { ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100001; vector<int> gra[MAXN], tgra[MAXN]; int timestamp, ans, dfn[MAXN], degree[MAXN], tmp[MAXN]; inline void read(int& x) { char c; for (c = getchar(); c <= 32; c = getchar()) ; for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0'; }; void df...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int di[] = {-1, 0, 1, 0, -1, 1, 1, -1}; const int dj[] = {0, 1, 0, -1, -1, 1, -1, 1}; const long long MOD = 1e9 + 7; const long long INF = 1e9; const long double EPS = 1e-7; class Graph { int V; list<int>* adj; void fillOrder(int v, bool visited[], stack<int>& S...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; const double pi = acos(-1.0); const int size = 200 * 1000 + 100; vector<int> vertex[size]; vector<int> dir[size]; int n, m; int col[size]; bool used[size]; vector<int> cur; bool flag = false; void dfs1(int v) { used[v] = true; ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); bool positive = 1; for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') positive = 0; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline char RC(...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.*; import java.math.*; import java.util.*; public class Main { public static boolean dag; public static int v[]; public static ArrayList[] uadj; public static void main (String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(Sys...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> Adj[100001]; vector<int> Edge[100001]; bool visited[100001]; bool checked[100001]; vector<int> v1; bool circle = false; bool in_stack[100001]; void DFS_un(int u, int p) { visited[u] = true; v1.push_back(u); for (vector<int>::iterator it = Adj[u].begin(); i...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, k, st[100001], sz[100001]; vector<pair<int, int> > edges; vector<int> g[100001], gt[100001], gs[100001]; bool mark[100001]; void first(int u, stack<int> &st) { mark[u] = true; for (int v : g[u]) if (!mark[v]) first(v, st); st.push(u); } void second(int u...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100009; const int oo = 1000; bool mark[N]; int visit[N]; int ans; vector<int> _list, ed[N], adj[N]; int ncompo; void DFS(int u) { mark[u] = 1; _list.push_back(u); for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (mark[v]) continue;...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; struct Node { int idx, ind; Node(int r, int in) : idx(r), ind(in) {} }; bool operator<(Node a, Node b) { return a.ind > b.ind; } const int maxn = 1e5 + 5; vector<int> G[maxn]; int ind[maxn], p[maxn], cnt[maxn]; int n, m, ans = 0; int Find(int x) { return p[x] == x ? x :...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; inline bool cbound(int x, int b, int e) { return ((x >= b) && (x <= e)); } inline int getint() { int a; cin >> a; return a; } inline long long getll() { long long a; cin >> a; return a; } inline double getdouble() { double a; cin >> a; return a; } vector<v...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; void DFS(int c, int v, const vector<vector<int> >& graph, vector<int>& comp) { comp[v] = c; for (int next : graph[v]) { if (next < 0) { next = -next - 1; } if (comp[next] == 0) { DFS(c, next, graph, comp); } } } int main(int argc, char** ar...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; const int maxn = 101010; const int lol = 30001; const int maxn4 = 4 * maxn; const long long inf = 2020202020202020202LL; vector<vector<int> > g(maxn); int n, m; int parent[maxn], rang[maxn], clr[maxn], deg[maxn], cl[maxn], d[maxn]; void make_set(i...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; bool okay, visited[100010], used[100010], visited2[100010]; int n, m; vector<int> v[100010]; vector<int> vec; vector<int> g[100010]; void dfs(int x) { visited[x] = 1; vec.push_back(x); for (int i = 0; i < (int)g[x].size(); i++) { if (!visited[g[x][i]]) dfs(g[x][i]...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> const int maxn = 1e5 + 15; using namespace std; int mark[maxn], id[maxn], cl[maxn], n, m, a, b, ans, comp; vector<int> vec[maxn], d[maxn]; bool finish[maxn]; void dfs(int v, int c) { id[v] = c; for (int u : vec[v]) if (!id[u]) dfs(u, c); } void cycle(int v) { mark[v] = 1; for (int u...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int f[100005]; int n, m; vector<int> e[100005]; queue<int> que; int F(int x) { if (f[x] == x) return x; return f[x] = F(f[x]); } bool H[100005]; int lt[100005]; bool vis[100005]; int c[100005]; void dfs(int cnt) { c[cnt] = -1; for (int i = 0; i < e[cnt].size(); i++)...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int const N = 3e5; int n, m, p[N], sz[N], order[N], v[N], outcnt, cnt, ans, was[N], anc; vector<int> edge[N], edgeT[N], comp[N]; void dfs(int u) { v[u] = 1; for (int i = 0; i < edge[u].size(); ++i) { int to = edge[u][i]; if (!v[to]) dfs(to); } order[outcnt++...
CPP