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;
stack<int> sk;
bool insk[100010], isok[100010];
int step, dfn[100010], low[100010], belong[100010], num[100010], tol;
struct Edge {
int to, next;
} edge[200010];
int head[100010], tail;
void add(int from, int to) {
edge[tail].to = to;
edge[tail].next = head[from];
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;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
for (int i = 0; i < (((int)(v).size())); ++i) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<... | 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:16000000")
using namespace std;
const int Maxn = 100005;
int n, m;
vector<int> rneigh[Maxn], neigh[Maxn];
int in[Maxn];
vector<int> seq;
bool tk[Maxn], tk2[Maxn];
int res;
void Traverse(int v) {
if (tk[v]) return;
tk[v] = true;
seq.push_back(v);
for (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;
const int inf = 1e9;
const double eps = 1e-9;
const int INF = inf;
const double EPS = eps;
struct __timestamper {};
vector<int> all1, all2;
vector<pair<int, int> > ces;
vector<bool> was1, was2;
vector<vector<int> > es, rves;
void dfs1(int v) {
if (was1[v]) return;
was1[... | 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>
void fre() {
freopen("c://test//input.in", "r", stdin);
freopen("c://test//output.out", "w", stdout);
}
template <class T>
inline void gmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, ... | 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];
vector<int> k[100100];
int used[100100];
vector<int> g2[100100];
bool check[100100];
bool use[100100];
int t = 1;
int N, M;
stack<int> s;
void dfs(int a) {
if (check[a]) return;
check[a] = true;
for (int i = 0; i < g[a].size(); i++) dfs(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;
vector<int> v[100010];
int p[100010], mark[100010], in[100010];
queue<int> que;
int Find(int x) { return p[x] == x ? x : (p[x] = Find(p[x])); }
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) p[i] = i;
while (m--) {
int x, y;
scanf... | 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 = 100 * 1000 + 10;
int n, m, comp[N], res, ans, sz[N], par[N];
vector<int> adj[N], _adj[N], topol;
vector<pair<int, int>> ed;
bool vis[N], cycle[N];
void dfs_topol(int v) {
vis[v] = true;
for (int u : adj[v])
if (!vis[u]) dfs_topol(u);
topol.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;
const int N = 100007;
vector<int> order, G[N], RG[N], S[N];
int n, m, compCnt, cnt, comp[N], size[N];
vector<pair<int, int> > edges;
bool used[N];
void dfs(int u) {
used[u] = true;
for (int to : G[u]) {
if (!used[to]) dfs(to);
}
order.push_back(u);
}
void rdfs(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;
vector<int> grafo[100001];
vector<int> grafo2[100001];
bool visitado[100001];
bool termino[100001];
bool hayciclo[100001];
bool ciclo;
int t;
void dfs(int u) {
visitado[u] = true;
for (int i = 0; i < grafo[u].size(); i++) {
int v = grafo[u][i];
if (!vi... | 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>
void fre() {
freopen("c://test//input.in", "r", stdin);
freopen("c://test//output.out", "w", stdout);
}
template <class T>
inline void gmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, ... | 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.*;
import java.io.*;
public class B
{
public static void main(String[] args)
{
PrintWriter out = new PrintWriter(System.out);
new B(new FastScanner(), out);
out.close();
}
public B(FastScanner in, PrintWriter out)
{
Graph orig = new Graph(in.nextInt());
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 | #include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
const int N = 1e5 + 5;
struct edg {
int to[N], nxt[N], cnt, head[N];
void add(int u, int v) {
cnt++;
to[cnt] = v;
nxt[cnt] = head[u];
head[u] = cnt;
}
} G1;
int read() {
int s = 0;
char ch = getchar();
while (!isdigit(ch... | 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 = 100005;
int n, m, u, v;
vector<int> g[N];
namespace SCC {
int dfn[N], low[N], id[N], st[N], _st, _, cc;
void dfs(int c, vector<int> g[]) {
dfn[c] = low[c] = ++cc;
st[_st++] = c;
for (auto t : g[c])
if (!dfn[t])
dfs(t, g), low[c] = min(low[c], l... | 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 = 2e9;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
stack<int> s;
int n, m, ans, low[N], num[N], h[N] = {0}, t[N] = {0};
vector<int> a[N], b[N];
void DFSt(int x) {
static int c = 0;
s.push(x);
num[x] = low[x] = --c;
for (vector<int>::iterator i = 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.*;
import java.util.*;
public class DMain {
String returnValue = "NoResult";
PrintWriter out;
Parser in;
static class City{
final int index;
int color;
boolean checked;
boolean suspected;
Vector<City> toCities = new Vector<City>();
Vector<... | 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>
#pragma comment(linker, "/stack:32000000")
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 100010;
vector<int> g2[maxn];
bool ok;
int used[maxn];
void dfscycle(int x) {
used[x] = 2;
for (int i = 0; i < int((g2[x]).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>
#pragma GCC optimize("O3")
using namespace std;
int n, m;
int usedWCC[((int)2e5 + 5)];
int mark[((int)2e5 + 5)];
int mark2[((int)2e5 + 5)];
vector<int> v[((int)2e5 + 5)];
vector<int> u[((int)2e5 + 5)];
vector<int> wcc[((int)2e5 + 5)];
int wccCount;
void dfs(int node) {
wcc[wccCount].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;
int n, m, dad[100010], x, y, gs[100010], head[200010], ne[1000010], v[1000010],
vis[200010], l, use[200010], i, ans, tot;
void add(int x, int y) {
v[++l] = y;
ne[l] = head[x];
head[x] = l;
}
int find(int x) { return dad[x] == x ? x : dad[x] = find(dad[x]); }
int d... | 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 ArrayList<Integer>[] adjList;
static int 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 | import java.util.*;
import java.io.*;
public class CF506B {
public static void main(String[] args) throws IOException {
in.init(System.in);
n = in.nextInt();
int m = in.nextInt();
adj = new ArrayList[n];
bid = new ArrayList[n];
for(int i = 0; i < n; i ++)
{
adj[i] = new ArrayList<Integer>();
bid[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 | #include <bits/stdc++.h>
using namespace std;
inline long long in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string getStr() {
char ch[200];
scanf("%s", ch);
return ch;
}
inline char getCh() {
char ch;
scanf(" %c", &ch);
return ch;
}
template <class P, class Q>
inline P smin(P &a, Q 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;
vector<int> E[100005];
int P[100005], S[100005];
int find(int i) { return (P[i] == i ? i : P[i] = find(P[i])); }
bool join(int i, int j) {
i = find(i), j = find(j);
if (i == j) return false;
if (S[i] > S[j]) swap(i, j);
P[i] = j;
S[j] += S[i];
return true;
}
boo... | 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 read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, m, scc, ind;
int dfn[100005], low[100005],... | 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 Task {
public static void main(String[] args) throws IOException {
new Task().solve();
}
PrintWriter out;
int cnt = 0;
int n;
boolean[] used;
ArrayList<Integer>[] g;
ArrayList<Integer>[] rg;
ArrayList<Integer> tsort = new ArrayList<Integer>();
int[] c... | 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 = 1e5 + 10;
int n, m, parent[maxN], num_comp, res, num[maxN], low[maxN], num_node,
unavail[maxN], comp[maxN], sze[maxN];
vector<int> adj[maxN];
stack<int> st;
struct Edge {
int u, v;
} e[maxN];
int get_root(int u) {
return (u == parent[u] ? u : (paren... | 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.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("outp... | 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;
struct edge {
int to, nxt;
} e[100005];
int head[100005], cnte, n, m;
void adde(int u, int v) {
e[++cnte] = (edge){v, head[u]};
head[u] = cnte;
}
int fa[100005];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) {
if ((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 | #include <bits/stdc++.h>
using namespace std;
vector<int> adj[(100005)];
int N, M;
pair<int, int> edges[(100005)];
int num_comp;
int comp[(100005)];
int num_members[(100005)];
int visited[(100005)];
bool cycle[(100005)];
void dfs(int at) {
num_members[num_comp]++;
comp[at] = num_comp;
visited[at] = true;
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.*;
import java.util.*;
public class Equal {
static int mod = (int) (1e9 + 7);
static ArrayList<Integer>[] adjList;
static int V, counter, c, SCC, dfs_num[], dfs_low[];
static boolean[] inSCC;
static Stack<Integer> stack;
static int ans;
static void tarjanSCC() // O(V + E)
{
counter = 0;
S... | 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 = 233333;
vector<int> g[maxn];
int r[maxn];
int f[maxn];
bool p[maxn];
queue<int> que;
int find(int u) {
int v = u;
while (v != f[v]) v = f[v];
while (u != f[u]) {
int w = f[u];
f[u] = v;
u = w;
}
return u;
}
int main() {
int n, m;
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;
const int SZ = 100101;
vector<int> g[SZ], g1[SZ];
vector<int> used;
int c[SZ], c_color[SZ], cnt[SZ];
void dfs(int u) {
used[u] = -1;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (!used[v])
dfs(v);
else if (used[v] == -1)
c[u] = 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 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class B {
static StringTokenizer st;
static BufferedR... | 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.util.ArrayList;
import java.util.Scanner;
public class DFSTEST {
static boolean[] components ;
static class Node{
ArrayList<Node> out = new ArrayList<>() , in = new ArrayList<>() ;
int component = 0 ;
int state = 0 ;
}
static void dfs(Node node , int component){
... | 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 = 100010;
int g_n, g_m;
vector<int> vvi_edge[maxn], has[maxn], vvi_uv[maxn];
int vi_dg[maxn];
int mark;
int vi_mark[maxn];
void dfs(int u) {
vi_mark[u] = mark;
int len = vvi_edge[u].size();
for (int i = 0; i < len; i++) {
int v = vvi_edge[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 | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class B {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.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 N = 100005;
int n, m, num, ans, col[N];
bool flag[N], vis[N], vis2[N];
vector<int> g1[N], g2[N];
void dfs1(int u) {
col[u] = num;
for (auto v : g2[u]) {
if (!col[v]) dfs1(v);
}
}
void dfs2(int u) {
vis[u] = vis2[u] = 1;
for (auto v : g1[u]) {
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, tot, m, ans;
vector<int> Ed[100005];
int pp[200005], ne[200005], he[200005], in[200005], g[200005], q[200005];
bool bo[200005];
inline int IN() {
char c;
register int first = 0;
while ((c = getchar()) < 48 && c ^ '-' || c > 57)
;
bool f = c == '-';
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 | import java.io.*;
import java.util.*;
public class B {
ArrayList<Integer>[] from;
ArrayList<Integer>[] to;
int[] color;
int[] tOut;
boolean[] mark;
int[] size;
int time;
void run() {
int n = in.nextInt();
int pairs = in.nextInt();
int[] a = new int[pairs];
int[] b = new int[pairs];
from = new Array... | 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.util.*;
public class R286qBMrKitayatuTech {
static int n,m,ans,s,count;
static ArrayList<Integer> forw[],revs[],list[];
static int vis[];
@SuppressWarnings("unchecked")
public static void main(String args[] ) throws Exception {
InputReader in = new InputReader(System.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 | // package Div2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
public class Sketch {
private static class Node {
public int src;
public int last;
public boolean isHead;
public boolean hasCircle;
pu... | 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 maxx = 1e5 + 20;
int markk[maxx];
bool hasCycle, mark[maxx];
vector<int> adj[maxx];
vector<int> nei[maxx];
vector<int> vec;
void DFS(int v) {
mark[v] = true;
vec.push_back(v);
for (int i = 0; i < adj[v].size(); i++)
if (!mark[adj[v][i]]) DFS(adj[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.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 int N = 1e5 + 1;
int m, n, ans = 0;
bool st[N], en[N];
vector<int> gr[N], lis[N];
int par[N];
bool DAG;
int fin(int u) {
if (par[u] == u) return u;
return par[u] = fin(par[u]);
}
void dj(int u, int v) {
int pu = fin(u), pv = fin(v);
par[pu] = pv;
}
void dfs(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 | import java.util.*;
import java.io.*;
public class Main {
static BufferedReader in;
static PrintWriter out;
public static void main(String[] arguments) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
CF48D solve = new CF48D(in,out);
solve.solve();
out.clo... | 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 = 1 << 30;
const long double eps = 1e-9;
vector<pair<int, int> > v[300000], ts;
int was[300000];
int colour;
int c[300000];
bool wc[300000];
bool topsort(int u) {
if (was[u] == 2) return true;
if (was[u] == 1) return false;
was[u] = 1;
bool res = 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;
const int N = 100010;
int n, m;
vector<long long> g[N];
vector<long long> rg[N];
vector<long long> vs;
bool used[N];
int cmp[N], cmpsize[N];
void add_edge(int from, int to) {
g[from].push_back(to);
rg[to].push_back(from);
}
void dfs(int v) {
used[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;
int n, m, cual;
vector<vector<int> > G, GT;
vector<int> scc;
vector<int> cuantosporssc;
vector<bool> ok;
stack<int> orden;
void dfs1(int curr) {
if (not ok[curr]) {
ok[curr] = true;
for (int adj : G[curr]) dfs1(adj);
orden.push(curr);
}
}
void dfs2(int curr)... | 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;
scanf("%d", &x);
return x;
}
const int INF = 1e9 + 10;
const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
const int MN = 1e5 + 10;
int mk[MN];
vector<int> adj[MN];
int n, m;
int col[MN];
vector<int> imp[MN], comp[MN];
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;
vector<int> Tp[100001], adj[100001], temp;
int n, m, C, Cyc, backT[100001];
bool vis[100001];
void TopS(int x) {
vis[x] = 1;
temp.push_back(x);
for (int i = 0; i < Tp[x].size(); i++) {
if (!vis[Tp[x][i]]) TopS(Tp[x][i]);
}
}
void CheckC(int x) {
backT[x] = 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 int64_t DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9 + 7;
const int N = 2e5 + 5;
int indeg[N];
struct DSU {
int n, components;
vector<int> data, rootID, roots;
DSU(int n)
: n(n),
components(n),
data(vector<int>(n + 1, -1)),
root... | 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 tot = 0, fa[400100], link[400100], size[400100], vis[400100], ans[400100],
final_ans = 0, n, m;
struct rec {
int num, next;
} e[1000010];
void add_edge(int x, int y) {
tot++;
e[tot].num = y;
e[tot].next = link[x];
link[x] = tot;
}
int get_fa(int x) {
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 double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x;
}
const int MAXN = 120 ... | 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.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
public final class CF_KitayutaTechnology {
... | 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 C;
vector<int> comp[100007];
int vi[100007];
int de[100007];
vector<int> g[100007];
vector<int> go[100007];
vector<int> gi[100007];
int I[100007];
int O[100007];
void DFS(int v, int p) {
if (vi[v]) return;
vi[v] = 1;
comp[C].push_back(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;
vector<vector<int> > g, dg, cs;
vector<int> gehort;
vector<bool> vis, loop;
void dfs1(int n) {
cs.back().push_back(n);
gehort[n] = cs.size() - 1;
vis[n] = 1;
for (int i = 0; i < g[n].size(); i++) {
if (!vis[g[n][i]]) dfs1(g[n][i]);
}
}
vector<bool> inStk;
stac... | 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 <class T>
bool uax(T& a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool uin(T& a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int N = 100500;
int c[N];
vector<int> g[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 maxn = 1e5 + 10;
int n, m;
int mark[maxn];
vector<int> G[maxn], adj[maxn];
bool res = 0;
int sz = 0;
vector<int> vec;
void dfs(int v) {
mark[v] = 1;
sz++;
vec.push_back(v);
for (int u : G[v])
if (!mark[u]) dfs(u);
}
void DFS(int v) {
mark[v] = 1;
f... | 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.ArrayList;
import java.util.Arrays;
public class CF506B {
static ArrayList<Integer>[] edges, redges;
static boolean[] topcol, compcol, cycle;
static int[] topsort;
static int topsortEnd;
static void topdfs(int i) {
if (topcol[i]) {
return;
... | 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 | 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 | import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
public class B {
static class SCC {
public static final int NULL = -1;
List<Integer>[] adj;
int dfsIndex;
int[] dfsNum;
int[] dfsLow;
... | 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 n, m;
int cost[200005];
struct edge {
int from;
int to;
int next;
} E[100005];
int head[200005];
int sz = 0;
void add_edge(int u, int v) {
sz++;
E[sz].from = u;
E[sz].to = v;
E[sz].next = head[u];
head[u] = sz;
}
stack<int> s;
int ins[200005];
int dfn[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 | 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.StringTokenizer;
public class KitayutaTechnology {
int[] in;
int[] low;
int[] group;
boolean[] groupHasCycle;
... | 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.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outp... | 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 n, m;
vector<int> g[100001];
vector<int> gg[100001];
bool vis[100001];
int bel[100001];
void dfs1(int x, int w) {
bel[x] = w;
vis[x] = 1;
for (int i = 0; i < gg[x].size(); i++) {
int v = gg[x][i];
if (vis[v]) continue;
dfs1(v, w);
}
}
int degree[1000... | 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, rt[100100], x[100100], y[100100];
int find_rt(int u) { return rt[u] == u ? u : rt[u] = find_rt(rt[u]); }
void link(int u, int v) {
u = find_rt(u), v = find_rt(v);
if (u != v) rt[u] = v;
}
vector<int> adj[100100], edge[100100], node[100100];
int C, col[100100],... | 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 = 200005;
long long N, M;
bool vis[100005], instack[100005];
vector<int> G[100005];
int par[100005], size[100005];
bool cycle[100005];
bool ok;
int findF(int x) { return par[x] == x ? x : findF(par[x]); }
void unionF(int x, int y) {
x = findF(x), y = findF(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;
template <typename T>
inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename 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;
int n, m;
vector<int> g[100500], f[100500];
char was[100500];
int C, cl[100500];
vector<int> a[100500];
void dfs1(int v) {
a[C].push_back(v);
was[v] = 1;
for (int i = 0; i < f[v].size(); ++i) {
int to = f[v][i];
if (!was[to]) dfs1(to);
}
return;
}
bool 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;
vector<int> been;
vector<vector<int> > sorted;
vector<vector<pair<int, bool> > > graph;
void dfs(int index) {
been[index] = 1;
for (int i = 0; i < graph[index].size(); i++)
if (!been[graph[index][i].first]) dfs(graph[index][i].first);
sorted[sorted.size() - 1].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 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-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 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> graph[maxn];
vector<int> g[maxn];
bool mark[maxn];
int n, m;
int par[maxn];
int cm[maxn];
bool comp[maxn];
int mk[maxn];
int moalefe[maxn];
void dfs(int x, int y) {
mark[x] = 1;
cm[x] = y;
moalefe[y]++;
for (int v : graph[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>
#pragma comment(linker, "/STACK: 1024000000,1024000000")
using namespace std;
const int N = 1e5 + 15;
struct Edge {
int u, v, nxt;
Edge() {}
Edge(int t2, int t3, int t4) : u(t2), v(t3), nxt(t4) {}
};
Edge e[N * 30];
int h[N], ect;
int low[N], dfn[N], vis[N], col[N], sz[N], s[N], tp, sm, 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;
const int N = 1e5 + 7;
const long long base = 1e18 + 7;
const long long mod = 1e9 + 7;
const int M = (1 << 9) + 7;
int n, m, pa[N], deg[N], sz[N];
bool cycle[N];
vector<int> ke[N];
queue<int> q;
int getroot(int u) {
if (u == pa[u]) return u;
return pa[u] = getroot(pa[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 = 1e5 + 5;
vector<int> G[maxn], E[maxn];
int n, m;
int vis[maxn];
vector<int> vec;
int C, col[maxn];
void dfs(int u) {
vis[u] = 1;
col[u] = C;
vec.push_back(u);
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (!vis[v]) dfs(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 recur_depth = 0;
const long long sz = 1e5 + 10;
vector<long long> g[sz], g2[sz], comp;
bitset<sz> ase;
long long tot, vis[sz], cyc = 0;
void dfs(long long u) {
vis[u] = 1;
for (long long& v : g[u]) {
if (!vis[v])
dfs(v);
else if (vis[v] == 1)
cyc... | 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 = 100005;
vector<int> v[N], u[N], w;
int c[N];
int d[N];
int n, m, a, b, ans;
int dfs(int i) {
c[i]++;
for (auto k : v[i]) {
if (c[k] == 1) return 1;
if (c[k] == 0 && dfs(k)) return 1;
}
c[i]++;
return 0;
}
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>
const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int kx[] = {2, 2, -2, -2, 1, -1, 1, -1};
const int ky[] = {1, -1, 1, -1, 2, 2, -2, -2};
bool check(int a, int p) { return (bool)(a & (1 << p)); }
int on(int a, int p) { return (a | (1 << p)); }
usi... | 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> adj[100005], dir[100005], vec;
int vis1[100005], vis2[100005], vis3[100005], fl = 0;
void dfs1(int u) {
vis1[u] = 1;
vec.push_back(u);
for (int i = (int)0; i <= (int)adj[u].size() - 1; i++) {
if (!vis1[adj[u][i]]) dfs1(adj[u][i]);
}
}
void dfs2(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 long long INF = 1e9 + 10;
const long long N = 1e5 + 10;
vector<long long> g[N], rg[N], gg[N], order;
long long c[N], x[N];
bool used[N], kek;
void dfs(long long v) {
used[v] = true;
for (auto u : g[v]) {
if (!used[u]) {
dfs(u);
}
}
order.push_bac... | 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, ans, l, r;
int line[MAXN];
int du[MAXN];
int nxt[MAXN];
bool boo[MAXN];
bool bbb[MAXN];
vector<int> v[MAXN];
int Find(int k) {
if (nxt[k] != k) nxt[k] = Find(nxt[k]);
return nxt[k];
}
int main() {
scanf("%d%d", &n, &m);
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 inf = 1e9;
const int mo = 1e9 + 7;
const int N = 2e5 + 10;
vector<int> mem[N], son[N];
int fa[N], du[N];
bool finish[N];
int getfa(int x) { return (fa[x] == x) ? x : (fa[x] = getfa(fa[x])); }
queue<int> Q;
int main() {
int n, m;
scanf("%d%d", &n, &m);
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 | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
using namespace std;
const int MAX = 100 * 1000 + 10;
int n, m;
int A[MAX], B[MAX];
vector<int> I[MAX], rI[MAX], G[MAX], rG[MAX];
vector<int> SCC[MAX];
int id[MAX], scc_cnt;
vector<int> ord;
bool vis[MAX];
void dfs(int u) {
if (vis[u]) re... | 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.lang.*;
public class Main {
final static String fileName = "";
final static boolean useFiles = false;
public static void main(String[] args) throws FileNotFoundException {
InputStream inputStream;
OutputStream outputStream;
if (useF... | 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 n, m;
vector<int> arr[100005];
vector<int> rev[100005];
int ans[100005];
int comp[100005];
int fans = 0;
vector<int> f;
bool vis[100005];
bool visC[100005];
bool flag;
int cnt, sumC;
void dfs(int v) {
vis[v] = true;
vector<int> tmp;
if (flag)
tmp = arr[v];
e... | 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;
int n, m;
bool foundCir, mark[MAXN], inPath[MAXN];
vector<int> adj[MAXN], adj2[MAXN], st;
void go1(int u) {
st.push_back(u);
mark[u] = 1;
for (int i = 0; i < int(adj2[u].size()); ++i) {
int v = adj2[u][i];
if (!mark[v]) go1(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 long long maxn = 3e5 + 10;
int n, m, ans;
vector<int> G[maxn], g[maxn], gr[maxn], comp;
bool mark[maxn], in[maxn], out[maxn];
bool dfs(int x) {
in[x] = 1;
for (int u : g[x]) {
if (in[u] && !out[u]) return 0;
if (!in[u] && !dfs(u)) return 0;
}
out[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 MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
vector<int> e[SIZE];
vector<pair<int, int> > pp;
bool used[SIZE];
int id, order[SIZE], num;
void dfs(int x) {
used[x] = 1;
num++;
for (int i = 0; i < (((int)(e[x]).size())); ++i) {
int y = e[x][i];
pp.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;
int Stack[100009], top;
int Index[100009], Lowlink[100009], Onstack[100009];
int idx, components;
vector<int> G[100009];
bool ok;
bool vis[100009];
int have;
vector<int> V[100009];
bool taken[100009];
int comp[100009];
void DFS(int u) {
if (vis[u]) return;
vis[u] = 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;
vector<vector<int> > v1(100005), v2(100005);
vector<int> v;
int u[100005];
int a[100005];
int r;
void dfs1(int cur) {
u[cur] = 1;
v.push_back(cur);
int i, x;
for (i = 0; i < v1[cur].size(); i++) {
x = v1[cur][i];
if (u[x] == 0) {
dfs1(x);
}
}
f... | 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 = 100010;
long long n, m, x, y, res, cycle;
long long cost[maxn];
vector<long long> adj[maxn], alt[maxn];
vector<long long> visited, col;
vector<long long> component;
stack<long long> order;
void dfs1(long long x) {
col[x] = 1;
for (auto i : adj[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 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 | #include <bits/stdc++.h>
using namespace std;
const double EPS = -1e8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
const int MAXN = 100010;
struct DSJ {
int mom[MAXN];
void init(int x) {
for (int i = 1; i <= x; i++) mom[i] = i;
}
int find(int x) { return mom... | 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 used[maxn], used2[maxn], exists[maxn], in[maxn];
vector<int> org[maxn], g[maxn];
vector<vector<int> > components;
int cur;
void dfs1(int v) {
if (used[v]) return;
used[v] = 1;
components.back().push_back(v);
for (auto i : g[v]) dfs1(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.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
/*
5 8
1 2
2 3
3 4
4 1
5 4
5 1
5 2
5 3
7 7
1 2
2 3
4 1
4 3
5 4
6 7
7 6
*/
public class d {
static class Graph
{
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;
int N, M;
vector<int> G[100005];
vector<int> GG[100005];
vector<int> Area[100005];
int Sort[100005], number, cycle;
int Poz[100005], area;
bool Use[100005];
void Read() {
cin >> N >> M;
for (int i = 1; i <= M; i++) {
int x, y;
cin >> x >> y;
G[x].push_back(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 id[300010], sz[300010], dg[300010];
vector<int> adj[300010], comp[300010];
void ufinit(int n) {
for (int i = 0; i < (n); ++i) id[i] = i, sz[i] = 1;
}
int uffind(int i) {
if (i == id[i]) return i;
return id[i] = uffind(id[i]);
}
void ufunion(int v, int w) {
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 | import java.io.*;
import java.util.*;
public class Main {
int[] p;
ArrayList<Integer>[] g;
int[] was;
int find(int x) {
if (p[x] != x) {
p[x] = find(p[x]);
}
return p[x];
}
boolean dfs(int x) {
was[x] = 1;
for (int y : g[x]) {
if (was[y] == 1) {
return false;
}
if (was[y] == 0) {
... | 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.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.LinkedHashSet;
import java.util.StringTokenizer;
public class MrKitayutasTechnology {
public static void main(String[] args) ... | 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 + 10, MAX = 2e5 + 1e4, MOD = 1e9 + 7, MAXL = 25;
void OUT(long double o, int x) {
cout << fixed << setprecision(x) << o;
return;
}
long long t[MAX], vis[MAX], mo = 0;
vector<int> adj[MAX], vec, ad[MAX], rev[MAX];
void dfs(int v) {
vis[v] = 1;... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.