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> using namespace std; const int N = 100 * 1000 + 20; int n, m, markTopol[N], ans; bool flag = false, mark[N]; vector<int> adj[N], out[N], ver; void dfs(int v) { mark[v] = true; ver.push_back(v); for (auto u : adj[v]) if (!mark[u]) dfs(u); } void dfs_topol(int v) { markTopol[v] = 1; ...
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()) 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]: setroot(cluster[...
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 long long int INF = (1LL << 58); const bool DEBUG = 0; const int NODES_LIMIT = 100005; int nodes, edges; std::vector<int> adj[2][NODES_LIMIT]; bool vis[NODES_LIMIT]; int color[NODES_LIMIT], globalColor = 1; int componentSize[NODES_LIMIT]; bool hasCycle[NODES_LIMIT]; 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; /** * @author Pavel Mavrin */ public class B { private void solve() throws IOException { int n = nextInt(); int m = ...
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 = 1000 * 100 + 5; const long long inf = 9223372036854775807; int n, m, mark[maxn], comp[maxn], ans, cnt = 1, sz[maxn]; pair<int, int> e[maxn]; vector<int> adj[maxn], g[maxn], radj[maxn], t; bool dfs2(int v) { bool b = true; if (sz[v] != 1) b = false; ma...
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 GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; inline void base() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(6); } 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; const int MAXN = 100 * 1000 + 14; vector<int> uadj[MAXN], adj[MAXN], vcomp; bool cycle; int visited[MAXN], vvisited[MAXN]; void uDfs(int v) { visited[v] = 1; vcomp.push_back(v); for (auto u : uadj[v]) { if (visited[u] == 0) uDfs(u); } } void dfs(int v) { vvisi...
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[100100], rg[100100], gg[100100], l[100100]; vector<int> vs; int pos[100100]; set<int> occur; bool vis[100100]; int cnt[100100]; int n, m, num; void dfs(int v) { vis[v] = 1; for (int i = 0; i < g[v].size(); i++) if (!vis[g[v][i]]) dfs(g[v][i]); vs.pus...
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_ = 100500; int N, M; vector<int> gph[N_], rev[N_], bth[N_]; int outdg[N_], indg[N_]; bool visited[N_]; vector<int> ord; void dfs(int u) { visited[u] = true; for (int i = 0; i < gph[u].size(); i++) { int v = gph[u][i]; if (!visited[v]) dfs(v); } o...
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> G[100001]; int pre[100001], dfs_clock, scc[100001], sccno; int S[100001], top; int fa[100001]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int cnt[100001]; int dfs(int u) { int lowu = pre[u] = ++dfs_clock; S[top++] = u; for (int i = 0; i < G...
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.HashSet; import java.util.StringTokenizer; import java.util.HashMap; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; ...
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.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 =...
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 = 100005; struct sx { int from, to, last; }; struct sl { sx line[N], fl[2 * N]; int last[N], color[N], sta[N], top, num, fnum, dfn[N], low[N], tot, colornum, fla[N], pointnum[N]; bool c[N], cc[N]; void add(int x, int y) { line[++num].to = y; ...
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> g[1000000]; vector<int> gdir[1000000]; int aridadin[1000000]; int visto[1000000]; void genera(int u, int &numnod, queue<int> &q) { if (visto[u]) return; visto[u] = 1; numnod++; vector<int> &ar = g[u]; if (aridadin[u] == 0) q.push(u); for (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.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Reader; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; 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 N = 1e5 + 5; vector<vector<int> > v, g, comp(1); char u[N]; int T = 0; bool CYCLE; void dfs0(int st) { u[st] = 1; comp[T].push_back(st); for (int i = 0; i < g[st].size(); ++i) { int to = g[st][i]; if (!u[to]) dfs0(to); } } void dfs(int st) { u[st...
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 = 100000; int n; vector<int> neigh[max_n]; int val[max_n]; int c; int s[max_n], s_ed; int b[2 * max_n], b_ed; void run_dfs(int v) { s[++s_ed] = v; val[v] = s_ed; b[++b_ed] = val[v]; for (int j = 0; j < int(neigh[v].size()); j++) { int w = neigh[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 MAXN = 100005; const int MAXE = 200005; struct Edge { int v, n; Edge() {} Edge(int v, int n) : v(v), n(n) {} }; Edge E[MAXE]; int H[MAXN], N[MAXN], cntE; int Q[MAXN], head, tail; int in[MAXN]; int n, m; int cnt; int p[MAXN], num[MAXN]; void clear() { cntE ...
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> mg[100005], um[100005]; int marka[100005], pos[100005], uk, niz[100005], f; void dfs(int cvor) { int i, x; pos[cvor] = 1; uk++; niz[uk] = cvor; for (i = 0; i < mg[cvor].size(); i++) { x = mg[cvor][i]; if (pos[x] == 0) dfs(x); } } void nciklus...
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 main() { cin.sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int> > G(N); vector<vector<int> > Gr(N); vector<int> D(N, 0); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; G[--a].push_back(--b); G[b].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
#include <bits/stdc++.h> using namespace std; vector<int> G[100005]; vector<int> rG[100005]; vector<int> vec; bool used[100005], done[100005], onstack[100005]; int n, m; void add_edge(int from, int to) { G[from].push_back(to); rG[to].push_back(from); } int wcc(int v) { int ret = 1; used[v] = true; vec.push_ba...
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 RI(int& x) { x = 0; char c = getchar(); while (!(c >= '0' && c <= '9' || c == '-')) c = getchar(); bool flag = 1; if (c == '-') { flag = 0; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } if (!fla...
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 = 1 << 28; const long long LINF = 1ll << 61; int n, m, ans; vector<int> con[100111], rev[100111], arr; int vis[100111], cycle; void dfs1(int x) { arr.push_back(x); vis[x] = 1; for (int i = 0; i < con[x].size(); i++) { int u = con[x][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 int maxn = 100500; int n, m, ans, scc, idx; int d[maxn], vis[maxn]; vector<int> g[maxn], e[maxn], vec; queue<int> q; void dfs(int u) { if (vis[u]) return; vis[u] = 1; vec.push_back(u); for (auto v : e[u]) { dfs(v); } } int main() { scanf("%d%d", &n, &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; int n, m, tot, ans, Head[100000 + 5], q[100000 + 5], T[100000 + 5], Deg[100000 + 5]; bool Flag[100000 + 5]; struct Edge { int next, node; } h[100000 + 5 << 1]; inline void addedge(int u, int v) { h[++tot].next = Head[u], Head[u] = tot; h[tot].node = v; } inline vo...
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.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.PrintStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import ...
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<vector<int> > adj, adj2; int D[200010]; int I[200010]; int V1[200010]; int V2[200010]; int SEEN, VIS; void dfs(int u, vector<int> &PV) { V1[u] = 1; PV.push_back(u); for (int i = 0; i < adj[u].size(); ++i) { int v = adj[u][i]; D[v]--; if (D[v] == 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; const int N = 100100; int n, m, u, v, color[N], f[N], sz[N], cycle[N], res; vector<int> g[N]; int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } void merge(int u, int v) { if ((u = find(u)) == (v = find(v))) return; if (sz[u] < sz[v]) swap(u, v); sz[u] += 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> using namespace std; int n, m, ptr; bool mark[100010]; bool bad[100010]; int ord[100010]; vector<int> dir[100010]; vector<int> rev[100010]; vector<int> adj[100010]; bool dfs(int idx) { bool ret = bad[idx]; mark[idx] = true; for (int i = 0; i < adj[idx].size(); i++) if (!mark[adj[idx][...
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 mxi = 1e5 + 666; const long long mod = 1e9 + 7; const long long inf = -1e17; int n, m, ans, mark[mxi], mark2[mxi]; vector<long long> g[mxi], ne[mxi], ts; bool cy; void tso(int v) { ts.push_back(v); mark2[v] = 1; for (auto u : ne[v]) { if (!mark2[u]) tso(...
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.List; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.ArrayList; import java.io.PrintStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.Collectio...
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.text.DecimalFormat; import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Reader in = new Reader(inputStream); PrintWriter out = new PrintWriter(ou...
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; template <class T> inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); } template <class T> inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); } template <class T> inline T BigMod(T Base, T power, T M = 1000000007) { if (power == 0) retur...
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 MX = 1e5 + 5; int low[MX], depth[MX], timer = 0, compcnt = 0, comp[MX], compsz[MX], vi[MX]; vector<int> adj[MX], adj1[MX]; stack<int> S; void dfs(int x) { low[x] = depth[x] = ++timer; S.push(x); vi[x] = 1; int sz_ = adj[x].size(), nxt; for (int j = 0; j ...
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; long long qpow(long long a, long long b) { long long res = 1, base = a; while (b) { if (b % 2) res = res * base; base = base * base; b /= 2; } return res; } long long powmod(long long a, long long b) { long long res = 1, base = a; while (b) { 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; long long power(long long x, long long y, long long mod) { if (y < 0) return power(power(x, mod - 2, mod), -y, mod); long long res = 1; while (y) { if (y & 1) res = res * x % mod; y >>= 1; x = x * x % mod; } return res; } const int nn = 100010; int v[n...
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 = 100005; vector<int> adj[MAX], neg[MAX]; int mark[MAX], mark2[MAX]; bool cycle; void dfs(int v) { mark[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; if (mark[u] == 1) cycle = true; if (!mark[u]) dfs(u); } mark[v] = 2...
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.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution ...
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 = 4 * 1e5 + 2; const int MOD = 1000000007; int n, m; vector<unordered_set<int>> vec; vector<unordered_set<int>> vec_rev; vector<bool> visited; stack<int> stk; vector<unordered_set<int>> SCC; vector<int> dsu; unordered_set<int> deleted; int getParent(int node) { ...
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; string s; long long rez, h, q, n, i, j, k1, k2, k3, d, x, k, y, xx, yy, m, l, r, c, t, sum, used[100500]; vector<long long> graph[100500], gr[100500], grb[100500]; vector<long long> comps[100500]; vector<long long> order; void dfs(int v) { if (used[v]) return; used[...
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 main(void) { srand(time(0)); cout << fixed << setprecision(7); cerr << fixed << setprecision(7); int n, m; ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n >> m; static vector<int> s[1 << 20]; static vector<int> v[1 << 20]; while (m--) { int 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
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public cl...
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 v[200005], h2[200005], in[200005], h[200005], tot = 0, k, n, m; struct edge { int y, ne; } e[400005]; queue<int> q; void Add(int x, int y) { tot++; e[tot].y = y; e[tot].ne = h[x]; h[x] = tot; } void Add2(int x, int y) { tot++; e[tot].y = y; e[tot].ne = h...
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 bian { int next, point; } b[210000]; int p[110000], len, in[110000], s[110000], dfs[110000], low[110000], pd[110000], now, sign, w[110000], size[110000], n, m; void ade(int k1, int k2) { b[++len] = (bian){p[k1], k2}; p[k1] = len; } void add(int k1, int k2) ...
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.InputStreamReader; import java.io.BufferedReader; import java.util.StringTokenizer; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.PrintWriter; import java.io.IOException; import java.util.Collections; import java.util.Arrays; import java.util.List; import java.util.Ar...
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 INF = 0x3f3f3f3f, MOD = 1e9 + 7; int n, m; int cmpsize[100010]; vector<int> G[100010]; vector<int> rG[100010]; bool vis[100010]; int cmp[100010]; vector<int> vs; void dfs(int v) { vis[v] = true; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i]]) 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 long long mod = 1e9 + 7; const int N = 3e5 + 5; int n, m, cnt, h[N], num, ser[N], low[N], dfn[N], tot, sta[N], top, siz[N], flag[N]; bool vis[N]; struct Edge { int to, next; } e[N]; int to[N], fa[N]; long long ans; void add(int u, int v) { e[++cnt] = (Edge){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, ok, k, v[100005], x, y, ans; vector<int> a[100005], b[100005], c; bitset<100005> w; void udfs(int x) { w[x] = 1; vector<int>::iterator it; c.push_back(x); for (it = b[x].begin(); it != b[x].end(); ++it) if (!w[*it]) udfs(*it); } void dfs(int x) { v[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 INF = 1000000000; const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; const int kaijou[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320...
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 = 100100; vector<int> g[maxn], dg[maxn]; int dfs_enter[maxn], dfs_f[maxn], n, m, cnt; bool visited[maxn]; bool cycle[maxn]; vector<int> st; void dfs(int node) { if (visited[node]) return; st.push_back(node); visited[node] = true; dfs_enter[node] = dfs...
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; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int maxn = 100010; int n, m; vector<int> adj1[maxn]; vector<int> ad...
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], f[100005], vc; int used[100005], n, m, cycle; bool visit[100005]; void dfs(int i) { int j, x; used[i] = 1; for (j = 0; j < g[i].size(); j++) { x = g[i][j]; if (used[x] == 1) cycle = 1; if (!used[x]) dfs(x); } used[i] = 2; } void ...
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 a[100000]; int par[100000]; vector<int> v[100000]; vector<int> w[100000]; int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; par[x] = y; } int main() { int n...
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 double PI = acos(-1.0); const long long INF = 1e9 + 47; const long long LINF = INF * INF; const int MAX = 100 * 1000 + 7; vector<int> g[MAX], gr[MAX]; int used[MAX]; vector<int> order, component; void dfs1(int v) { used[v] = 1; for (int i = (0); i < ((int)((g[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, t, r, rez; vector<int> G[100005], GT[100005], C[100005]; vector<int> H[100005]; char viz[100005]; struct nod { int a, b; }; nod A[100005]; bool mark[100005], good[100005]; void read() { scanf("%d%d", &n, &m); int x, y; while (m) { scanf("%d%d", &x, &y)...
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 + 1000; const int maxE = maxN << 1; int n, m; int h[maxN], nxt[maxE], to[maxE], e; int ind[maxN]; int vis[maxN]; int que[maxN], qh, qt; int que2[maxN], qh2, qt2; int main() { e = 0; memset(h, -1, sizeof h); scanf("%d %d", &n, &m); for (int i = 1...
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 n, m; vector<int> arc[maxn], meta[maxn]; stack<int> stk; int ind, ans; int dis[maxn], low[maxn]; bool vs[maxn]; int T; int sccid[maxn]; int cycle[maxn]; void tarjan(int u) { vs[u] = true; dis[u] = low[u] = T++; stk.push(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; void prologue() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } const int MAX = 100007; bool visited[MAX]; vector<vector<int>> g, rg; vector<int> finish; vector<int> scc; void ddfs(int node) { if (visited[node]) return; visited[node] = t...
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> g1[111111], g2[111111], dfn, g3[111111]; int N, M, C[111111], gcnt, gnum, P[111111]; int ans, S[111111], chk; void dfs(int node) { int i; C[node] = 1; for (i = 0; i < g1[node].size(); i++) if (!C[g1[node][i]]) dfs(g1[node][i]); dfn.push_back(node); }...
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; struct edge { int u, v, st, nt; } e[MAXN * 2]; vector<int> lis; int hd[MAXN], etot, used[MAXN], in[MAXN], u[MAXN], v[MAXN]; void addedge(int u, int v, int st) { e[etot].u = u; e[etot].v = v; e[etot].st = st; e[etot].nt = hd[u]; hd[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.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.ListIterator; import java.util.StringTokenizer; public class Main implements Runnable { ArrayList<Integer>[] v = new ArrayList[100100]; ArrayList<Integer>[] vo = new ArrayL...
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 = 100005; int n, m, vis[N], du[N]; vector<int> a[N], b[N]; queue<int> q; int dfs(int x) { vis[x] = 1; int ans = 1; if (du[x] == 0) q.push(x); for (int i = 0; i < a[x].size(); i++) if (!vis[a[x][i]]) ans += dfs(a[x][i]); return ans; } int main() { ...
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> order, all[100001], g[100001]; int n, m, x, y, ans, color[100001], i; bool cycle, u[100001]; void dfs1(int v) { u[v] = true; order.push_back(v); for (int j = 0; j < all[v].size(); j++) { int to = all[v][j]; if (!u[to]) dfs1(to); } } void dfscolor...
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 = int(1e9); const double eps = 1e-9; const double pi = 4 * atan(double(1)); const int N = int(1e5) + 100; bool cyc; int sz; int use[N]; bool used[N]; int lst[N]; vector<int> g[N], g2[N]; void dfs1(int v) { used[v] = true; lst[sz++] = v; for (int i = 0; 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, color[100010], cont_color[100010]; vector<int> adj[100010], radj[100010], st; bool ctrl[100010]; int g(int ind) { int res = cont_color[color[ind]] == 1; ctrl[ind] = true; for (int i = 0; i < adj[ind].size(); i++) { if (!ctrl[adj[ind][i]]) res &= g(adj[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; vector<int> dfs_num; vector<vector<int> > wccs; vector<int> sccs; vector<vector<int> > graph; vector<vector<int> > graph_rev; int wcc, leader; stack<int> korasaju; void dfs_aux(int v) { dfs_num[v] = 1; wccs[wcc].push_back(v); for (int i = 0; i < graph[v].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 Mod = 1e9 + 7; inline int FIX(long long a) { return (a % Mod + Mod) % Mod; } const int N = 1e5 + 5; vector<int> E[N]; int n, m; int fa[N]; int find_set(int rt) { return fa[rt] == rt ? rt : (fa[rt] = find_set(fa[rt])); } void union_set(int x, int y) { fa[find_set...
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.*; public class HW1_ex5 { static ArrayList<Node> outOfNode; static int k; static int[] component; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); Graphs firstGraph ...
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; using vint = vector<long long>; using pint = pair<long long, long long>; using vpint = vector<pint>; template <typename A, typename B> inline void chmin(A& a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A& a, B b) { if (a < b) a = 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
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 123; int n, m, charger, charge[MAXN], miz; vector<int> g[MAXN], rev[MAXN]; stack<int> st; bool mark[MAXN], maze[MAXN], iss; void inp(); void dfs(int); void solve(); void rfs(int); void cfs(int); int main() { ios_base::sync_with_stdio(0); ci...
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 Graph { int n; vector<vector<int>> adj; vector<vector<int>> rev; vector<bool> was; vector<int> color; vector<int> mark; Graph(int _n) : n(_n), adj(_n + 1), rev(_n + 1), was(_n + 1), color(_n + 1), mark(_n + ...
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 CF; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class D { static ArrayList<Integ...
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[100005], g[100005], st; int vis[100005]; int mk[100005]; int flag; void dfs(int v) { st.push_back(v); vis[v] = 1; for (int i = 0; i < G[v].size(); i++) { int to = G[v][i]; if (!vis[to]) dfs(to); } } void dfs2(int v) { mk[v] = 1; 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; template <typename T> struct Pt { T x, y; void scan() { cin >> x >> y; } }; template <typename T> inline T sqr(const T& a) { return a * a; } template <typename T> inline int sign(const T& a) { return a < 0 ? -1 : a > 0; } void task(); int main() { task(); 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> using namespace std; struct edge { int to; int next; } e[210000], E[310000]; int head[200010], bian, bian2, head2[200010]; void add(int x, int y) { bian++; e[bian].next = head[x]; head[x] = bian; e[bian].to = y; } void add2(int x, int y) { bian2++; E[bian2].next = head2[x]; he...
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.InputStreamReader; import java.io.IOException; import java.util.ArrayList; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.TreeSet; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution...
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 = 100000 + 5; int fa[N], cnt[N], ru[N]; vector<int> G[N]; queue<int> qu[N]; int n, m; int find_fa(int x) { return fa[x] = fa[x] == x ? x : find_fa(fa[x]); } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) fa[i] = i; int u, v; 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
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Main { FastScanner in = new FastScanner(); PrintWriter out; ArrayList<Integer> g[]; ArrayList<Integer> rg[]; LinkedList<Integer> vl = new LinkedList<>(); boolean vis[]; int ...
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 = 100 * 1000 + 10; int n, m, u, v, ans, d[maxn], cur; vector<int> vec[maxn], a[maxn][2], M, topol; bool mark[maxn], park[maxn], flg; void dfs(int x) { park[x] = 1; M.push_back(x); for (int i = 0; i < ((int(vec[x].size()))); i++) { if (!park[vec[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> using namespace std; int M; const int N = 100005; vector<int> v[N]; vector<int> to[N]; int seen[N]; int in[N]; vector<int> cur; void dfs(int at) { seen[at] = 1; for (auto(i) = (0); (i) < ((int)v[at].size()); (i)++) { int next = v[at][i]; if (!seen[next]) dfs(next); } cur.push_ba...
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 int MOD = 1e9 + 7; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[...
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> graph[100010]; vector<int> sg[100010]; bool visited[100010]; vector<int> cc[100010]; int cmp; void dfs(int node) { cc[cmp].push_back(node); visited[node] = true; for (int i = 0; i < (int)sg[node].size(); i++) { int next = sg[node][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 n, m; vector<int> gf[100000 + 3]; vector<int> gb[100000 + 3]; char used[100000 + 3]; char tused[100000 + 3]; vector<int> s; void tsort(int v) { tused[v] = 1; for (int i = 0; i < gf[v].size(); i++) { int to = gf[v][i]; if (!tused[to]) { tsort(to); }...
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.Reader; import java.util.Arrays; import java.util.ArrayList; import java.util.InputMismatchException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; p...
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 INF = 1e9 + 9; const int N = 1e5 + 10; vector<int> v[N]; int low[N], dfn[N]; int in[N], s[N]; int sz[N]; int cnt, scccnt, top; int flag[N]; int ans = 0; class UnionSet { public: int fa[N]; void init() { memset((fa), (-1), sizeof(fa)); } int treesize(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 MAXV = 100005; int P[MAXV]; int R[MAXV]; int S[MAXV]; void init(int N) { for (int i = 0; i < N; i++) { P[i] = i; R[i] = 0; S[i] = 1; } } int rep(int i) { if (P[i] != i) P[i] = rep(P[i]); return P[i]; } bool unio(int a, int b) { a = rep(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 = 100100; int dfn[N], low[N], sccno[N], scc_cnt, idx, sz[N]; stack<int> st; vector<int> g[N]; vector<int> cc[N], dd[N]; void dfs(int u) { dfn[u] = low[u] = ++idx; st.push(u); for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (!dfn[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<int> u[100005]; vector<int> u2[100005]; bool s[100005]; int deg[100005]; int n, m; vector<int> c; void fc(int i) { s[i] = true; c.push_back(i); for (int j : u2[i]) if (!s[j]) fc(j); } int Q[100005], qs, qe; bool topsort(vector<int> v) { qs = qe = 0; 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; vector<int> ady[100005], tra[100005]; bitset<100005> b; int cmp[100005], cnt[100005]; stack<int> s; void dfs(int curr) { b[curr] = 1; int next; for (int i = 0; i < (int)ady[curr].size(); ++i) { next = ady[curr][i]; if (b[next] == 0) dfs(next); } ...
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> > grafo; vector<vector<int> > grafoinv; vector<int> tams; int cont = 0; int n, m; bool comp; bool trace[100005]; bool vis[100005]; stack<int> pila; int uf[100005]; int siz[100005]; bool ciclo[100005]; bool toc[100005]; void initUF(int n) { 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> #pragma comment(linker, "/STACK:100000000") using namespace std; const long double pi = acos(-1.0); const int N = (int)1e5 + 10; vector<int> adj[N]; int color[N], u, v, p[N], n, m; bool bad[N], cycled; int dsu_find(int v) { return (v == p[v]) ? v : (p[v] = dsu_find(p[v])); } 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
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(100005); int cycle; vector<int> a[MAXN], b[MAXN], component; bool visited[MAXN]; int color[MAXN]; void dfs(int node) { visited[node] = 1; component.push_back(node); for (int i = 0; i < a[node].siz...
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>> adj, radj; int n, m; vector<int> vis; vector<int> belongto; vector<int> sz; vector<pair<int, int>> edges; stack<int> s; int itr; void dfs(int pos) { vis[pos] = 1; for (int &nxt : adj[pos]) if (!vis[nxt]) dfs(nxt); s.push(pos); } int dfs2(int po...
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 = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; using namespace std; const int N = 1e5 + 7; const int M = -1; vector<int> e[N], g[N]; int vis1[N], vis2[N], cyc[N], done[N], id[N]; void dfs1(int u, int c) { vis1[u] = 1; id[u] = c; for (int v : g[...
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[100010]; bool vis[100010]; set<int> s; vector<int> uf; vector<int> sz; bool cycle; int root(int a) { if (uf[a] == a) return a; return uf[a] = root(uf[a]); } void join(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (sz[a] > sz[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
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int n, m; int Stop, Bcnt, Dindex, DFN[MAX], LOW[MAX], Stap[MAX], Belong[MAX], num[MAX], used[MAX]; bool instack[MAX]; vector<int> G[MAX], g[MAX], gg; void tarjan(int i) { int j; DFN[i] = LOW[i] = ++Dindex; instack[i] = true; Stap[++Stop] ...
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 = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; inline long long gcd(long long a, long long b) { 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 MAXN = 1e5 + 50; vector<int> adj[MAXN], rev[MAXN]; int n, m; void readInput() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v); rev[v].push_back(u); } } bool vis[MAXN]; 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
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class Main { static int n, m; static boolean[] visited; static List<Integer> list; public static vo...
JAVA