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
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static ArrayList<Integer> a[]; static boolean visited[]; static void dfs(int i) { visited[i] = true; for (int j = 0; j < a[i].size(); j++) { if (!visited[a[i].get(j)]) ...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
n,m=map(int,raw_input().split()) w=[[] for _ in xrange(n)] p=[0] for _ in xrange(m): a,b=map(lambda x: int(x)-1,raw_input().split()) if w[a].count(b)==0: w[a].append(b) w[b].append(a) for k in xrange(n): t=[] for i in set(p): for wi in w[i]: t.append(wi) p.extend(t) if len(set(p))==n: brea...
PYTHON
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Queue; import java.util.Scanner; public class Main { static int n; static boolean[] visitedV = new boolean[100]; static boolean...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.*; import java.io.*; public class B { static int N , a , b ; static ArrayList<Integer> [] adjList ; static boolean [] marked ; public static void main(String[] args) throws IOException { // Scanner sc = new Scanner(new File("src/in.txt")); Scanner sc = new Scanner(Sy...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; long double EPS = 1e-9; long long cel(long long a, long long b) { if (a == 0) return 0; return ((a - 1) / b + 1); } long long gcd(long long a, long long b) { if (a < b) swap(a, b); return (b == 0) ? a : gcd(b, a % b); } long long MIN(long long a, int b) { long lon...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import defaultdict n, m = map(int, input().split()) adj = defaultdict(list) for i in range(m): x, y = map(int, input().split()) adj[x].append(y) adj[y].append(x) ok = False cmps = [] v = [0]*(n+1) for i in ra...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
from collections import defaultdict n, m= map(int, input("").split()) class Graph(): def __init__(self): self.nodes = {i:Node(i) for i in range(1, n + 1)} def find(self, i): if self.nodes[i].parent_id != i: new_parent_id = self.find(self.nodes[i].parent_id) self.nodes[i...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class C { String s = null; String[] ss = null; String F = "FHTAGN!"; String N = "NO"; int n; int m; class Edge{ public int t = 0; } List<Integer>[] edges = null; public void run() throws Exception{ BufferedReader br = null; File file = new File("...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> G[1005]; int vis[1005]; int padre[1005]; int ciclos = 0; int tot = 0; void dfs(int u) { vis[u] = 1; tot++; for (int i = (0); i < (G[u].size()); i++) { int v = G[u][i]; if (!vis[v]) { padre[v] = u; dfs(v); } else if (padre[u] != v an...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class CF199A { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); DisjointSet DJ = new DisjointSet(N); ArrayList<Integer>[] array = ne...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
// package Graphs; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class CTHULHU { public static void dfs(HashMap<Integer,Integer> a[],int curr,boolean visited[]){ visited[curr]=true; HashMap<Integer,Integer> friends=a[c...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.*; public class Main { static int n, m; // λ…Έλ“œ, μ—£μ§€ static ArrayList<ArrayList<Integer>> list = new ArrayList<>(); static int[] visit; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); if (n !...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
v, e = map(int, input().split()) E, V = [], set( range(1, v+1) ) for _ in range(e): a, b = map(int, input().split()) E.append([a, b]) sets = [ set([vertex]) for vertex in V ] def getSet(vertex): for s in sets: if vertex in s: return s in_tree = 0 for edge in E: a, b = edge if a in V: V...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
read = lambda: map(int, input().split()) n, m = read() graph = [set() for _ in range(n + 1)] for __ in range(m): u, v = read() graph[u].add(v) graph[v].add(u) def find_cycle(start): parents, stack = [0] * (n + 1), [(start, -1)] while stack: vertex, parent = stack.pop() parents[vertex] = parent f...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
n, m = [int(i) for i in input().split()] c = [int(i) for i in range(n+1)] def find (u): if u == c[u]: return u c[u] = find(c[u]) return c[u] ciclos = 0 for i in range(m): x, y = [int(j) for j in input().split()] x = find(x) y = find(y) if find(x) != find(y): c[x] = c[y] = m...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.ArrayList; public class Main { private static StreamTokenizer in; private static PrintWriter out; static { in = new StreamTokenizer(new BufferedReader(new InputStreamReade...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Created by IntelliJ IDEA. * User: alexsen * Date: 3/25/12 * Time: 9:49 PM * To change this template use File | Settings | File Templates. */ public class Fhtagn { protected static int n = 0; protected stati...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class B { public static void solution(BufferedReader reader, PrintWriter writer) throws IOException { In in = new In(reader); Out out = new Out(writer); int n = in.nextInt(), m = in.nextInt(); UnionFind uf = new UnionFind(n); ...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> G[100]; bool B[100]; vector<pair<int, int> > T; void dfs(int v, int p) { B[v] = true; for (int(i) = (0); (i) < (G[v].size()); ++(i)) { int to = G[v][i]; if (to == p) continue; if (B[to] == true) { T.push_back(make_pair(min(v, to),...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; void dfs(int v, vector<vector<int>>& g, vector<bool>& used) { if (!used[v]) { used[v] = true; for (auto u : g[v]) dfs(u, g, used); } } int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n + 1); vector<bool> used(n + 1); for (int i = 0; i < m; ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; bool q(vector<vector<int>>& a, vector<int>& v, vector<int>& s, int i, int p) { v[i] = 1; s.push_back(i); for (int j = 0; j < a[i].size(); j++) { if (v[a[i][j]] == 0) { bool t = q(a, v, s, a[i][j], i); if (t) return true; } else if (a[i][j] != p) { ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkmin(T &a, T b) { if (a > b) a = b; } const int N = 100; void dfs(int n, int x, bool *graph, bool *visited) { for (int i = 0; i < n; i++) { int y = i; if (graph[x * N + y] && !visited[y]) { visited[y] = true; dfs...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int vis[110] = {0}; void dfs(int v); vector<int> adj[110]; int main() { int n, m, x, y, i; scanf("%d", &n); scanf("%d", &m); for (int i = (int)0; i < (int)m; i++) { scanf("%d", &x); scanf("%d", &y); adj[x].push_back(y); adj[y].push_back(x); } if ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int ind = 0, n; int used[101]; int g[101][101]; void dfs(int v) { used[v] = 1; for (int k = 1; k <= n; k++) if (g[v][k] == 1) if (used[k] == 0) dfs(k); else if (used[k] == 2) ind++; used[v] = 2; } int main() { int m; cin >> n >> m; ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Iterator; import java.util.NoSuchElementException; import java....
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b /...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> int main() { int n, m; int col[200]; int a, b; int i, j; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) col[i] = i; for (i = 0; i < m; i++) { scanf("%d %d", &a, &b); a--; b--; for (j = 0, b = col[b]; j < n; j++) if (col[j] == b) col[j] = col[a]; } for (i...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; int par[400]; int a[400]; int union_find(int m) { if (par[m] == m) return m; return par[m] = union_find(par[m]); } int main() { ios_ba...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, i, x, sum, y; vector<int> a[105]; bool visit[105]; void dfs(int i) { visit[i] = 1; sum++; for (int j = 0; j < a[i].size(); j++) if (!visit[a[i][j]]) dfs(a[i][j]); } int main() { cin >> n >> m; for (i = 0; i < m; i++) { cin >> x >> y; a[x].pus...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> adj[102]; bool vis[102]; void f(int v) { vis[v] = 1; for (int i = (0); i < (adj[v].size()); ++i) { int u = adj[v][i]; if (!vis[u]) f(u); } } int main(int argc, char **argv) { int N, M; cin >> N >> M; if (M != N) { puts("NO"); return 0...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; int n, m; bool getcycle(int second) { bool visited[100] = {0}; stack<vector<int> > st; int cycles = 0; vector<int> start; start.push_back(second); st.push(start); visited[second] = 1; while (!st.empty()) { vector<int> v = st.top()...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
def findSet(u): if parent[u] != u: parent[u] = findSet(parent[u]) return parent[u] def unionSet(u, v): up = findSet(u) vp = findSet(v) if up == vp: return if ranks[up] > ranks[vp]: parent[vp] = up elif ranks[up] < ranks[vp]: parent[up] = vp else: ...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; long long int Mod = 1000000007; void dfs(int v, vector<int> G[], bool visited[]) { visited[v] = true; for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; if (!visited[u]) { dfs(u, G, visited); } } } int main() { int n, m; cin >> n >> m; ve...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
/* * Author- Priyam Vora * BTech 2nd Year DAIICT */ import java.io.*; import java.math.*; import java.util.*; import javax.print.attribute.SetOfIntegerSyntax; public class Graph1 { private static InputStream stream; private stati...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
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.StringTokenizer; public class temp { static ArrayList<Integer> graph[]; static int n; static boolean visited[]; public s...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.Scanner; public class Main { static int count=0,n; public static void DFS(ArrayList<ArrayList<Integer>> A,boolean vis[]) { for (int i = 1; i < n+1; i++) { if (!vis[i]) { DFS(A,i,vis); count++; } } } public static void DFS(ArrayList<ArrayList<Integer>>...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; long long n, m, x, y; bitset<105> visit; vector<long long> v[105]; void dfs(long long x) { visit[x] = true; for (int i = 0; i < v[x].size(); i++) { if (visit[v[x][i]] == false) { dfs(v[x][i]); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> std::vector<int> adj[100]; bool cycle = false; bool adding = false; int color[100]; std::vector<int> cyc; bool on_cyc[100]; void dfs1(int v, int p) { if (color[v] == 1) { cycle = true; adding = true; cyc.push_back(v); return; } color[v] = 1; for (int u : adj[v]) { if...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Cthulhu { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); ArrayList<Integer> list[] = new...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import static java.lang.Math.*; import java.util.*; import java.io.*; public class _80_d2_C2 { boolean[][] g = new boolean[110][110]; boolean[] vis = new boolean[110]; public void solve() throws Exception { int n = nextInt(), m = nextInt(); for (int i=0; i<m; ++i) { int a=nex...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
from collections import deque n, m = map(int, raw_input().split(' ')) if n != m: print 'NO' else: # the graph input link = [None] * (m+1) for i in range(m): x, y = map(int, raw_input().split(' ')) if not link[x] is None: link[x].append(y) else: link[x] = [y] if...
PYTHON
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
''' https://codeforces.com/problemset/problem/104/C ''' def findSet(u): if parents[u] != u: parents[u] = findSet(parents[u]) return parents[u] def unionSet(u, v): up, vp = findSet(u), findSet(v) if up == vp: return if ranks[up] > ranks[vp]: parents[vp] = up elif ranks[up] < ran...
PYTHON
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
function trim(s) { return s.replace(/^\s+|\s+$/gm, ''); } function tokenize(s) { return trim(s).split(/\s+/); } function tokenizeIntegers(s) { var tokens = tokenize(s); for (var i = 0; i < tokens.length; i += 1) { tokens[i] = parseInt(tokens[i], 10); }; return tokens; } function printValues() { var parts = ...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
//package codeforces; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; i...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
def read_input(): global n, m, edge n, m = map(int, input().split()) edge = [] for i in range(m): u, v = map(int, input().split()) edge.append((u-1, v-1)) def init(): global lab lab = [-1] * n def find_set(u): global lab if lab[u] < 0: return u lab[u] = fin...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.awt.*; import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; public class BetaRound80_Div1_B implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args) { new Th...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
def dfsxx(visited,adj,ind, parent): if(visited[ind]==1): return visited[ind]=1 for i in adj[ind]: if(visited[i]==0): dfsxx(visited,adj,i,parent) def dfs(visited,adj,ind,parent): if(visited[ind]==1): return [-1,-1] visited[ind]=1 for i in adj[ind]: if(visited[...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
def dfs(x): global f, tot, t #print x f[x] = True tot += 1 if tot == n: return for i in xrange(n): if a[x][i]: if f[i]: t += 1 if t >= 2: break a[x][i] = a[i][x] = False #print x + 1, i + 1 ...
PYTHON
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.*; import java.io.*; public class Ktuhlu { /** * @param args */ class Vertex { public int num; public boolean wasVisited = false; Vertex(int a) { num = a; } } BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); Ktuhlu() { try { solve(); } catch(IOExcep...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int visited[101]; int p[101]; int flag; int totalVisited(0); void SCC(int parent, vector<vector<int> > &adjList) { visited[parent] = 1; totalVisited++; for (int i = 0; i < (int)adjList[parent].size(); i++) { int child = adjList[parent][i]; if (!visited[child])...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 10000; vector<int> graph[N]; vector<int> cycles[N]; void dfs_cycle(int u, int p, int color[], int mark[], int par[], int& cyclenumber) { if (color[u] == 2) { return; } if (color[u] == 1) { cyclenumber++; int cur = p; mark[c...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#!/usr/bin/env python N, M = map(int, raw_input().split()) if N != M: print "NO" exit else: V = [[0] * N for i in xrange(N)] for i in xrange(M): u, v = map(int, raw_input().split()) V[u-1][v-1] = V[v-1][u-1] = 1 cnt = 0 H = [False] * N def dfs(v): if H[v]: return ...
PYTHON
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
def cycle(f): v = f cyc[v] = True v = p[v] while v != f: cyc[v] = True v = p[v] def dfs(v, par): global c, p if c[v] == 2: return p[v] = par if c[v] == 1: cycle(v) return True c[v] = 1 for u in graph[v]: if u != par: ...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long MAXN = 1e2 + 5; const double eps = 1e-8; vector<int> vec[MAXN]; int maze[MAXN][MAXN] = {0}; int vis[MAXN] = {0}; int evis[MAXN][MAXN] = {0}; int ok; int ringpos = -1; int dfs(int x) { vis[x] = 1; for (int i = 0; i < vec[...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.util.Random; public class B103 { static StreamTokenizer sc; static int[]p; public static void main(String[] args) throws IOException{ sc = new StreamTokenizer(n...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.awt.*; import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; public class _BetaRound80_Div1_B implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args) { new T...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 50; int n, m, u, v, cnt, cycle; vector<int> l[N]; unordered_map<int, bool> visited; void dfs(int u) { if (visited[u]) { return; } cnt++; visited[u] = true; for (auto i : l[u]) { if (!visited[i]) { dfs(i); } } } int main() { ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
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.StringTokenizer; public class A { static boolean[][] adjMat; static int N, count; static boolean[] visited; static voi...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
n, m = map(int, input().split()) if n < 3 or n != m: # minimo 3 vertices para un circulo print("NO") else: V = [] S = [] for i in range(n+1): #Armado de lista para conexiones de vertices V.append([]) for j in range(m): x, y = map(int, input().split()) V[x].append(y) ...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> const int N = 100 + 10; int fa[N]; int find(int x) { if (fa[x] != x) fa[x] = find(fa[x]); return fa[x]; } void Union(int x, int y) { x = find(x); y = find(y); fa[x] = y; } int main() { int n, m, x, y; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) fa[i] = i; for (int i = ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
def makeSet(n): global parent, ranks parent = [i for i in range (n + 1)] ranks = [0 for i in range(n + 1)] def findSet(u): if u != parent[u]: parent[u] = findSet(parent[u]) return parent[u] # 4 # | # 3 # / \ # 1 - 2 - 5 - 6 # N == M # 1 group ...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int N = (int)(1e2) + 1; vector<int> g[N]; int vis[N]; void dfs(int s) { vis[s] = 1; for (int i : g[s]) { if (!vis[i]) dfs(i); } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[x].push_back(y)...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class Ktulhu implements Runnable { public static void main(String[] args) { new Thread(new Ktulhu()).run(); } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer in; PrintWriter out = new PrintWriter(System.out); public String...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
from collections import defaultdict import sys n, m = [int(num) for num in sys.stdin.readline().split(' ')] edges = [] for i in range(m): edges.append([int(num) for num in sys.stdin.readline().split(' ')]) graph = defaultdict(list) for e in edges: graph[e[0]].append(e[1]) graph[e[1]].append(e[0]) visited...
PYTHON
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.Scanner; public class B103 { private static ArrayList<Integer> arr; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt();// vertices int m = sc.nextInt();// edges int[][] graph = new int[n][n]; for (...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const double eps = 1e-8; const double pi = acos(-1.0); bool g[110][110]; int n, m; bool vis[110]; int flag; bool dfs(int u, int f) { vis[u] = 1; for (int i = 1; i <= n; i++) if (i != f && g[u][i]) { if (vis[i]) { if (flag == 2)...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") struct VectorHash { size_t operator()(const std::vector<int> &v) const { std::hash<int> hasher; size_t seed = 0; for (int i : v) { seed ^= hasher(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2)...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> void dfs(int curVertex, int const& n, int& cnt, bool const* const* const graph, bool* const vis) { vis[curVertex] = true; cnt++; for (int i = 0; i < n; i++) { if (graph[curVertex][i] && !vis[i]) { dfs(i, n, cnt, graph, vis); } } } int main() { size_t n = 0; si...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> parent; vector<int> sz; int isles(0); void make_set(int u) { parent[u] = u; sz[u] = 1; } int find_set(int u) { if (parent[u] == u) { return u; } return parent[u] = find_set(parent[u]); } void union_set(int a, int b) { a = find_set(a); b = find_...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> struct Edge { int u, v, next; } edge[100000]; int head[105], num[105]; bool visited[105]; int en, cnt, tt; void add_edge(int u, int v) { edge[en].u = u; edge[en].v = v; edge[en].next = head[u]; head[u] = en++; } void DFS1(int u) { int v; visited[u] = true; for (int id = head[u];...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class C implements Runnable { public void solve( ) throws Throwable { int v = in.nextInt( ); boolean g[ ][ ] = new boolean[ v ][ v ]; int edges = in.nextInt( ); for ( int i = 0; i < edges; ++i ) { int a = in.nextInt( ...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; template <typename T> T pow(T a, T b, long long int m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } template <typename T> void swap(T *a, T *b) { T temp = *a; *a = *b; *b = temp; r...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> q[208]; bool used[208]; int p[208]; int find(int x) { if (p[x] == x) return x; return p[x] = find(p[x]); } int main(void) { bool flag = 0; int n, m, i, j, x, y; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) p[i] = i; for (i = 1; i <= m; i++) { ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.Stack; public class Prob103B { public static void main( String[] Args ) { Scanner scan = new Scanner( System.in ); int v = scan.nextInt(), e = scan.nextInt(); if ( v != e ) Syste...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, u, v, cnt = 0; vector<int> g[3002]; bool vis[3002]; void dfs(int s) { cnt++; vis[s] = true; for (int i = 0; i < g[s].size(); i++) { if (!vis[g[s][i]]) dfs(g[s][i]); } } int main() { scanf("%d%d", &n, &m); if (n != m) { cout << "NO" << endl; ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> g[101]; int n, m; bool visited[101]; void dfs(int v) { visited[v] = true; for (int i = 0; i < g[v].size(); i++) { if (!visited[g[v][i]]) dfs(g[v][i]); } } bool isConnected() { fill(visited, visited + n, false); dfs(0); for (int i = 0; i < n; i++)...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class Main implements Runnable { private BufferedReader in; private PrintWriter out; private StringTokenizer st; private void eat(String line) { st = new StringTokenizer(line); } private String next() throws IOException { while (!st.hasMoreTokens()) { Strin...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 105; bool check[maxn] = {false}; vector<vector<int> > edge(maxn); stack<int> s; void DFS(int x) { check[x] = true; s.push(x); bool ok = 0; while (!s.empty()) { int head = s.top(); s.pop(); for (auto itr1 : edge[head]) { if (!check[...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int ind = 0, n; int used[101]; int g[101][101]; void dfs(int v) { used[v] = 1; for (int k = 1; k <= n; k++) if (g[v][k] == 1) if (used[k] == 0) dfs(k); else if (used[k] == 2) ind++; used[v] = 2; } int main() { int m; cin >> n >> m; ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> v[10000]; int Visited[10000], parent[10000]; int cnt = 0; void DFS(int num) { Visited[num] = 1; for (int I = 0; I < v[num].size(); I++) { int val = v[num][I]; if (Visited[val] && parent[num] != val) { cnt++; continue; } if (parent...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; long long n, m; vector<vector<long long> > adj_list; vector<bool> visited; long long cnt = 0; void dfs(long long node) { visited[node] = true; ++cnt; for (auto neigh : adj_list[node]) { if (!visited[neigh]) { dfs(neigh); } } } int main() { ios_base::...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (nu...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import defaultdict n, m = map(int, input().split()) adj = defaultdict(list) for i in range(m): x, y = map(int, input().split()) adj[x].append(y) adj[y].append(x) cmps = 0 v = [0]*(n+1) for i in range(1, 1+n): ...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner r = new Scanner(System.in); int n = r.nextInt(); int m = r.nextInt(); boolean[][] g = new boolean[n][n]; for(int k = 0; k < m; k++){ int i = r.nextInt()-1; int j = r.nextIn...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class Main { // class Scanner { // StreamTokenizer in; // // Scanner(InputStream stream) { // in = new StreamTokenizer(new BufferedReader(new // InputStreamReader(stream))); // in.resetSyntax(); // in.whitespaceChars(0, 32); // in.wordChars(33, 2...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int sz = 1e6 + 10; using ll = long long; int n, m; int par[105]; set<int> st; int find_rep(int x) { return par[x] == x ? par[x] : par[x] = find_rep(par[x]); } int main() { while (scanf("%d %d", &n, &m) == 2) { for (int i = 0; i <= n; i++) par[i] = i; for (in...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int arr[110]; int root(int a) { while (arr[a] != a) { a = arr[a]; } return a; } void uni(int u, int v) { int rtu = root(u); int rtv = root(v); arr[rtv] = arr[rtu]; } int main() { int n, m; cin >> n >> m; for (int i = 0; i < 110; i++) { arr[i] = i; ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
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.StringTokenizer; public class Main1 { static FastReader input = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public stati...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; int n; int num[110]; int parent[110]; bool adjMat[110][110]; int numberOfCycles = 0; void dfs(int cur) { num[cur] = 789; for (int i = 1; i <= n; i++) if (adjMat[cur][i]) { if (num[i] == 135) { parent[i] = cur; dfs(i); } else if (num[i] ==...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; public class Octopus { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList<HashSet<Integer>> nodes = new ArrayList...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { static int N; static int M; static int edge[][]; static boolean taken[]; static int checkConnectivity(int node)...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 110; int p[N]; vector<int> adj[N]; int n, m; bool vis[N]; int S = 0, E = 0, cnt = 0; void dfs(int u) { vis[u] = 1; for (auto v : adj[u]) { if (!vis[v]) { p[v] = u; dfs(v); } else if (p[u] != v) { if (v == S && u == E) continue; ...
CPP
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
class Graph(): def __init__(self, number_nodes): self.nodes = [0] * (number_nodes+1) for i in range(number_nodes): self.nodes[i+1] = Node(i+1) def connect(self, node_1, node_2): self.find(node_1).neighbors.append(self.find(node_2)) self.find(node_2).neighbors...
PYTHON3
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import static java.lang.Math.*; import java.util.*; import java.io.*; public class _80_d2_C { boolean[][] g = new boolean[110][110]; boolean[] vis = new boolean[110]; int n; public void solve() throws Exception { n = nextInt(); int m = nextInt(); int v = n; for (int i=0; ...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; imp...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; public class Main { static class UnionFind { Map<Integer, Node> map = new HashMap<>(); class Node { int val; Node parent; int rank; public Node(int val) { this.val = val; } } public void makeSet(int u) { Node newNode = new Node(u); newNode....
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf103b { static BufferedReader __in; static PrintWriter __out; static StringTokenizer input; static int par[], deg[], sz[]; static int find(int u) { return par[u] == u ? u...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.LinkedList; import java.util.Scanner; import java.util.Stack; public class Main2 { static Scanner s = new Scanner(System.in); static int n,m; static Node[][] map = null; static int[][] checkMap = null; static LinkedList<Integer>[] startWith = null; static LinkedList<Integer>[] endWith = null; ...
JAVA
103_B. Cthulhu
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
2
8
import java.util.*; /** * Cf104C */ public class Cf104C { static int arr[][]; static boolean isCycle = false; static boolean visited[]; static int n, foundNodes = 0, cycles = 0; static void dfs2(int node) { if(!visited[node]) { //System.out.println("Visit " + node); ...
JAVA