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.Scanner; public class Cthulhu { static int[][] graph; static int num; static int result=0; static int[] check; public static void main(String[] args) { Scanner sc = new Scanner(System.in); num = sc.nextInt(); check = new int[num + 1]; int edge = sc...
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; import java.math.BigInteger; import java.util.ArrayList; import java.util.LinkedList; import java.util.Stack; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException...
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.lang.*; import java.io.*; public class Codechef { static PrintWriter out=new PrintWriter(System.out);static FastScanner in = new FastScanner(System.in);static class FastScanner {BufferedReader br;StringTokenizer stok;FastScanner(InputStream is) {br = new BufferedReader(new InputStr...
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()) a=[[0 for j in xrange(n)]for i in xrange(n)] for i in xrange(m): x,y=map(int,raw_input().split()) a[x-1][y-1]=a[y-1][x-1]=1 b=[0 for j in xrange(n)] t=0 cycle=[] def rec(q,q1): global t global cycle if b[q]==1: cycle.append(q) t=1 ret...
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.Scanner; public class Main { static int vNum; static int eNum; static boolean[][] graph; static boolean[][] graph2; static boolean[] used; static int[] cc; static int cycleQuantity = 0; static int ccNum; public static void main(String[] args) { Scanner sca...
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.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Cthulhu { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub //System.o...
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 long long N = 105; const long long INF = 100000000000; const long long mod = 1000000007; long long parent[N]; void pre() { for (int i = 0; i < N; i++) parent[i] = i; } long long root(long long v) { return parent[v] = (v == parent[v]) ? v : root(parent[v]); } void ...
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
# Problem from Codeforces # http://codeforces.com/problemset/problem/103/B parent = dict() ranks = dict() def make_set(N): global parent, ranks parent = [i for i in range(N + 5)] ranks = [0 for i in range(N + 5)] def find_set(u): if parent[u] != u: parent[u] = find_set(parent[u]) retur...
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.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { private static int n; private static int m; private static int[] root, size, deep; static int cicles; public static void main(String[] args) throws IOException { Bu...
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
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
#include <bits/stdc++.h> using namespace std; void dfs(int node, vector<int> adj[], bool vis[], int &flag, int par) { if (vis[node]) return; vis[node] = true; flag += 1; for (auto it : adj[node]) { if (!vis[it]) dfs(it, adj, vis, flag, node); } } int main() { int n, m; cin >> n >> m; vector<int> adj...
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.InputStreamReader; import java.util.ArrayList; import java.util.LinkedList; public class B103 { static class guy { LinkedList<guy> guys; public guy() { guys = new LinkedList<guy>(); } public void die() { guys.poll().guys.remove(this); } public void ad...
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; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static int cycle=0; public static void main(String[] args) throws NumberFormatException, IOException { ...
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 M = 100; vector<int> adj[M]; bool seen[M]; int n, m; int ans; int find_cycle(int p, int u) { seen[u] = 1; for (int i : adj[u]) { if (i == p) continue; if (seen[i] || find_cycle(u, i)) return 1; seen[i] = 0; } return 0; } void dfs(int u) { see...
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 cmp(pair<long long int, char> p1, pair<long long int, char> p2) { return p1.first > p2.first; } long long int k = 0; vector<vector<long long int> > graph; vector<long long int> vis, cycvisit; vector<long long int> cycedge; bool ans = false; void dfs(long long int nod...
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.Scanner; public class spinningTree { public int [] parentNodes; spinningTree(int n) { parentNodes = new int[n]; for (int i=0;i<n;i++){ parentNodes[i]=i+1; } } public int find_set(int x){ if (x==parentNodes[x-1]){ return x; } return parentNodes[x-1]=find_set(parentNodes[x-1]); ...
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 cthulhuCF { public static int disjoint[]; public static int size[]; public static int find(int v) { if (disjoint[v] == -1) { return v; } disjoint[v] = find(disjoint[v]); return disjoint[v]; } public static void union(int u, int v) { int uroot = find(u); int vr...
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 = 150; int a, b, c, n, m; int root[N]; void make_set(int vertex) { root[vertex] = vertex; } int find_set(int vertex) { if (root[vertex] != vertex) root[vertex] = find_set(root[vertex]); return root[vertex]; } void union_set(int vertex1, int vertex2) { int ...
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 father[105]; int find(int x) { if (x != father[x]) father[x] = find(father[x]); return father[x]; } int main() { int n, m; while (scanf("%d%d", &n, &m) != EOF) { int a, b, i; for (i = 1; i <= n; i++) father[i] = i; for (i = 1; i <= m; i++) { scanf("%d%d", &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
import java.util.Scanner; public class Cthulhu { static int counter = 0 ; static int n ; static int size ; static boolean[][] g ; static boolean[] visited ; public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); ...
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> #pragma comment(linker, "/STACK:16777216") using namespace std; long long INF = 1000 * 1000 * 1000; vector<int> p; vector<int> r; void make_set(int v) { p[v] = v; r[v] = 0; } int find_set(int v) { if (v == p[v]) return v; return p[v] = find_set(p[v]); } void union_set(int a, int 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
import java.io.DataInputStream; import java.io.InputStream; public class Cthulhu { static boolean w [][]; static boolean ww [][]; static int cycle [] ; static int ic = 0; static boolean ch []; static int cyc = -1; static int n ; static int reach ; public static void main(String [] args) throws Exception{ F...
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; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Task103B { static boolean[] visited; static List<List<Integer>> g; public static void main(String[] args) throws IO...
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; import java.io.PrintStream; import java.util.StringTokenizer; public class Main { public BufferedReader input; public PrintStream output; public StringTokenizer stoken = new StringTokenizer(""); int n; int m; int mas [...
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 = 110; int n, m; int fa[maxn]; bool vis[maxn]; int findset(int x) { return fa[x] == -1 ? x : fa[x] = findset(fa[x]); } int Bind(int u, int v) { int fu = findset(u); int fv = findset(v); if (fu != fv) { fa[fu] = fv; return 1; } return 0; } 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; long long n, m, st = -1, en = -1, c = 0, t = 0; vector<long long> ad[105]; map<long long, long long> vis, p; void dfs(long long i, long long pa = 0) { p[i] = pa; t++; vis[i] = 1; for (auto x : ad[i]) { if (x == pa) continue; if (vis[x]) { c++; } el...
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.*; public class Cthulu { public static class Graph { public int V; ArrayList<Integer> adjList[]; public Graph(int V) { this.V = V; adjList = new ArrayList[V]; for(int i = 0; i < V ; i++){ adjList[i] = new A...
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 Main implements Runnable { boolean[] visited; public void solve() throws IOException { int n = nextInt(); int m = nextInt(); if (n != m) { System.out.println("NO"); return; } boolean[][] board ...
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
num_nodes,num_edges = map(int,input().split()) edges = {} for i in range(num_edges): node1,node2 = map(int,input().split()) keys = list(edges.keys()) if node1 in keys: edges[node1].append(node2) else: edges[node1]=[node2] if node2 in keys: edges[node2].append(node1) else: edges[node2]=[node...
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 int INF = 1e18; const long long int N = 1e5 + 5; long long int mod = 998244353; void dfs(long long int node, long long int rank, vector<long long int> &vis, vector<vector<long long int>> &g, long long int &cnt) { vis[node] = rank; for (auto &nbr...
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 MAX_N = 100; vector<int> g[MAX_N]; vector<bool> mark(MAX_N, false); void dfs(int v, int n) { int vis = 0; stack<int> s; s.push(v); mark[v] = true; while (s.empty() == false) { int u = s.top(); vis++; s.pop(); for (int i = 0; i < g[u].size...
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.awt.geom.Point2D; import java.text.*; import java.math.*; import java.util.*; public class Main implements Runnable { final String filename = ""; boolean[] meetBefore; boolean[][] a; public void deepSearch(int x) { for (int i = 0; i < a[x].length; i++) if (a[x][i] && !meetBef...
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, cnt = 0; bool vst[101] = {}, g[101][101] = {}; inline void dfs(int a) { ++cnt; vst[a] = 1; for (int i = 1; i <= n; ++i) if (g[a][i] && !vst[i]) dfs(i); } int main() { int m, x, y; scanf("%d%d", &n, &m); if (n == m) { while (m--) { scanf("%d%...
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
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author JAVA */ public class C_800 { static boolean v[][]; static int count = 0; static boolean t[]; static int n; public static void main(String[] args) {...
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 = 1e2 + 5; int vis[N], n, m; vector<int> adj[N]; void DFS(int u) { vis[u] = 1; for (auto v : adj[u]) { if (!vis[v]) DFS(v); } } int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); 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
#include <bits/stdc++.h> using namespace std; string FILENAME = "filename"; struct dsuNode { int V, R = 0; dsuNode* P = NULL; dsuNode(int val) { V = val; } }; dsuNode* dsuID(dsuNode* ND) { dsuNode* old = ND; while ((*ND).P != NULL) ND = (*ND).P; if (old != ND) (*old).P = ND; return ND; } void dsuJoin(dsuN...
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 maxN = 100 + 10; int n, m; bool mark[maxN]; int par[maxN]; vector<int> v[maxN]; bool be[maxN][maxN]; int ans = 0; void dfs(int x) { mark[x] = true; for (int i = 0; i < v[x].size(); i++) { int tmp = v[x][i]; if (mark[tmp] == false) { par[tmp] = x;...
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; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int vis[100007], cnt, h...
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.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class Cthulhu { static ArrayList<Integer> [] adj; static boolean [] visited; public static void dfs(int u) { visited[u]=true; 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
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 50; int n, m, u, v, cnt, cycle; vector<int> l[N]; int visited[N]; void dfs(int u, int par) { if (visited[u] == 1) { cycle++; return; } if (visited[u] == 2) { return; } cnt++; visited[u]++; for (auto i : l[u]) { if (i != par ...
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> #pragma GCC optimize("O3") using namespace std; template <class T> inline T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> inline T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> inline T max(T a, T b, T c, T d) { return max(a, max(b, c, d)); } te...
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
n, m = map(int, input().split()) if n < 3 or n != m: print('NO') exit() e, f = [[] for i in range(n + 1)], set() for j in range(m): x, y = map(int, input().split()) e[x].append(y) e[y].append(x) def dfs(x): f.add(x) for y in e[x]: if not y in f: dfs(y) dfs(1) print('FHTAG...
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.ArrayList; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Eslam Ashraf */ public class C80 { static boolean [][] g; static int [] visit; static int n ; static int [] parent; static...
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
r=lambda:map(int,raw_input().split()) n,m = r() graph = [[] for i in range (n+1)] for i in range(m): s,t = r() graph[s] += [t] graph[t] += [s] visit = set() def dfs(u): visit.add(u) for v in graph[u]: if(not (v in visit)): dfs(v) dfs(1) if len(visit) == n == m: print("FHTAGN!") else: print("NO")
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.InputStreamReader; import java.util.Stack; import java.util.StringTokenizer; public class Ctulhu { /** * Ctulhu & Co * @author AAM */ public static final int ADJ = 1; public static final int NADJ = 0; public static final in...
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 ClosingTweets { static ArrayList<Integer>[] list; static boolean[] visited; public static void dfs(int i){ visited[i]=true; for(int x:list[i]){ if(!visited[x]){ dfs(x); } } } public static void main(String args[] ) throws Exception {...
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<long long int> g[1000]; long long int c = 1, vis[1001]; void DFS(long long int k) { vis[k] = 1; for (long long int i = 0; i < g[k].size(); i++) { if (!vis[g[k][i]]) { DFS(g[k][i]); c++; } } } int main() { long long int n, m; cin >> n >> ...
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 maxn = 120; int n, m; vector<int> adlist[maxn]; bool visited[maxn]; int vt[maxn]; int t = 0; void input() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; adlist[a].push_back(b); adlist[b].push_back(a); ...
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.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Cthulhu { static ArrayList<Integer> adjlis...
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 const MAXN = 2e5 + 10, MAXM = 2e6 + 10; long long n, m, T, a[MAXN]; long long e[MAXN], ne[MAXM], h[MAXN], idx, vis[MAXN]; void add(long long a, long long b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; } long long tmp = 0; void dfs(long long u, long long fa) { fo...
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; vector<vector<int> > adj; bool visi[300]; int back; void dfs(int u, int p) { visi[u] = true; for (int i = 0; i < (int)(int((adj[u]).size())); i++) { int v = adj[u][i]; if (v == p) continue; if (visi[v]) { back++; } else dfs(v, 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.util.Arrays; import java.util.Scanner; public class Cthulhu { Scanner in; void solve() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); if (n != m) { System.out.println("NO"); return; } Disjo...
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, cur = 0; vector<vector<int> > g; vector<char> used; void dfs(int v) { used[v] = true; for (int i = 0; i < g[v].size(); ++i) { int to = g[v][i]; if (!used[to]) { dfs(to); } } } int main(int argc, char *argv[]) { scanf("%d%d", &n, &m); 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 n, m; int f[103]; int find(int x) { if (x == f[x]) return x; return f[x] = find(f[x]); } void up(int x, int y) { int fx = find(x); int fy = find(y); f[fx] = fy; } int main() { while (~scanf("%d%d", &n, &m)) { for (int i = 1; i <= n; i++) f[i] = i; 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer ...
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; string vow = "aeiou"; int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; const long doubl...
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
//I AM THE CREED /* //I AM THE CREED /* package codechef; // don't place package name! */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.awt.Point; public class Main{ static int[] g=new int[101]; ...
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 = 300010; int n, m, fa[105]; int g[105][105], deg[105]; queue<int> q; int fnd(int x) { return fa[x] == x ? x : fa[x] = fnd(fa[x]); } int main() { scanf("%d%d", &n, &m); if (m != n) { printf("NO"); return 0; } for (int i = 1; i <= n; i++) fa[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 Solution { static int used[], cnt=0; static ArrayList<ArrayList<Integer>> g; public static void dfs(int v){ used[v] = 1; cnt++; for (int i = 0; i < g.get(v).size(); i++) if (used[g.get(v).get(i)]==0) dfs(g.get(v).get(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
/* * BATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPR * BATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPROBATPR * BAT. `PROBATPROBA|\___/|TPROBATPROB' .ATP * BATPR. `OBATPROBAT| |PROBATPROBA' .TPROB * BATPRO. `BAT...
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> adj[101]; bool vis[101]; void dfs(int u) { vis[u] = true; for (auto v : adj[u]) { if (!vis[v]) dfs(v); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int M = m; while (M--) { int u, v; cin...
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 long double PI = 3.1415926535897923846; const long long int MOD = 1000000007; const long long int N = 998244353; long long int power(long long int x, long long int n) { long long int res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD;...
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.math.*; import java.io.*; public class C { private void solve() throws IOException { int n = nextInt(); int m = nextInt(); boolean[][] adj = new boolean[n][n]; for (int i = 0; i < m; i++) { int from = nextInt() - 1; int to = 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
#include <bits/stdc++.h> const int maxn = 105; int n, m, fa[maxn], cnt; bool flag; inline int find(int x) { if (fa[x] != x) fa[x] = find(fa[x]); return fa[x]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); ...
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; /** * Created by IntelliJ IDEA. * User: alexsen * Date: 3/25/12 * Time: 9:49 PM */ public class Fhtagn { protected static int n = 0; protected static int m = 0; public static void main(String[] args){ ...
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 long long int N = 500000; vector<long long int> g[N]; long long int color[N]; void dfs(long long int k, long long int par, long long int &cyclenumber) { if (color[k] == 2) return; else if (color[k] == 1) { cyclenumber++; return; } color[k] = 1; f...
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, a, b; bool vis[101]; vector<int> edges[101]; void dfs(int u) { vis[u] = 1; for (int i = 0; i < edges[u].size(); ++i) if (!vis[edges[u][i]]) dfs(edges[u][i]); } bool spojny() { dfs(1); for (int i = 1; i <= n; ++i) if (!vis[i]) return 0; return 1; ...
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
prev = {} def dfs(g): root = g.keys()[0] prev[root] = None visited = {root:1} Q = [root] cycle_pts = []#[(father,son),...] while len(Q) > 0: v = Q[-1]#Q.pop() #print "v:",v has_neighbor = False for x in g[v]: #print "sosed:", x if not visit...
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
n, m = [int(i) for i in input().split()] adj = [[] for i in range(n+1)] seen = [False for i in range(n+1)] pai = [0 for i in range(n+1)] ciclos = 0 def dfs (u): seen[u] = True global ciclos for v in adj[u]: if not seen[v]: pai[v] = u dfs(v) elif v != pai[u]: ...
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> int fa[1010]; int find(int x) { if (x != fa[x]) fa[x] = find(fa[x]); return fa[x]; } int main() { int n, m; while (~scanf("%d%d", &n, &m)) { for (int i = 1; i <= n; i++) fa[i] = i; int flag, a, b, num, flag2; flag = num = flag2 = 0; for (int i = 0; i < m; i++) { sc...
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, a[100][100]; int col[100]; int cycles; void dfs(int p, int u) { col[u] = 1; for (int i = 0; i < n; i++) if (a[u][i] && i != p) { if (col[i] == 1) cycles++; if (col[i] == 0) dfs(u, i); } col[u] = 2; } int main() { cin >> n >> m; int x,...
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.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.*; public class apples { static ArrayList<Integer> ar[]; static boolean visited[]; static int count; static vo...
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; import java.util.ArrayList; public class Cthulhu { static ArrayList<Integer>[]adjList; static int []dfs_num; //0-->UNVISITED 1-->VISITED 2-->EXPLORED static int []dfs_parent; static int cycles=0; public static void mai...
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 n,m=map(int, raw_input().split()) d=defaultdict(list) for i in range(m): u,v=map(int,raw_input().split()) d[u].append(v) d[v].append(u) vis = [0]*(n+1) q=[1] vis[1]=1 c=0 while q: x=q.pop() c+=1 for i in d[x]: if not vis[i]: q.append(i) ...
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
#include <bits/stdc++.h> using namespace std; int m, n, s; bool vis[102]; vector<int> q[102]; void dfs(int a) { vis[a] = true; s++; for (int i = 0; i < q[a].size(); i++) if (vis[q[a][i]] == false) dfs(q[a][i]); } int main() { cin >> n >> m; int r1, r2; for (int i = 0; i < m; i++) { cin >> r1 >> r2; ...
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.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; import java.util.StringTokenizer; public class Solution { int n; int m; boolean[][] a; boolean[] b; int count;...
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<vector<int> > adj; vector<int> order, m, cc; int cycle = 0, cnt = 0; int cycle_check(int here) { int ret = order[here]; m.push_back(here); for (int there : adj[here]) { if (order[there] == -1) { order[there] = order[here] + 1; ret = min(ret, cyc...
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
A, B=map(int,input().split()) A_=[[] for i in range(A)] for i in range(B): a, b=map(int,input().split()) A_[b-1].append(a-1) A_[a-1].append(b-1) color=[0 for i in range(A)] def dfs(a): global color color[a]=1 for i in A_[a]: if color[i]==0: dfs(i) dfs(0) if sum(color)==A: ...
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 MAX_N = 444; vector<int> graph[MAX_N]; bool was[MAX_N]; void dfs(int u) { was[u] = true; for (int i = 0; i < graph[u].size(); i++) { int to = graph[u][i]; if (!was[to]) dfs(to); } } int main() { ios_base::sync_with_stdio(false); int n, m; int 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
#include <bits/stdc++.h> using namespace std; long long parent[10001]; long long cnt = 0, cnt1 = 0; void make_set(int v) { parent[v] = v; } int find_set(int v) { if (v == parent[v]) return v; return find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a == b) cnt++; 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; bool vis[105]; vector<int> g[105]; int dfs(int u) { vis[u] = true; for (int i = 0; i < g[u].size(); i++) { int to = g[u][i]; if (!vis[to]) dfs(to); } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; ...
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.util.Stack; public class D { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String input=br.readLine(); ...
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 int n, m, loopCount; static boolean[] isVisited; static int[][] g; private static void solve(InputReader in, OutputWriter out) { n = in.nextInt(); m = in.nextInt(); g = new int[n + 1][n + 1]; for (int 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
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj(105); vector<int> vis(105, 0); int vert; void dfs(int src) { vis[src] = 1; vert++; for (auto i : adj[src]) { if (!vis[i]) dfs(i); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int ...
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
# 103B __author__ = 'artyom' 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() ...
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.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class graph { static ArrayList<Intege...
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 Cthulhu { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int m = scan.nextInt(); if(n != m){ System.out.println("NO"); return; } ArrayList<Integer>[] adj = new ArrayList[n]; for(int i = 0; i < n; 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
class Node: def __init__(self, parent, rank): self.parent = parent self.rank = rank def findRoot(s, u): if s[u].parent != u: s[u].parent = findRoot(s, s[u].parent) return s[u].parent def union(s, u, v): ru = findRoot(s, u) rv = findRoot(s, v) if ru != rv: if s[ru].rank < s[rv].rank: ...
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; int n, m; void dfs(vector<int> tab[], int a, bool vis[]) { if (!vis[a]) vis[a] = true; for (int i = 0; i < tab[a].size(); ++i) { if (!vis[tab[a][i]]) { dfs(tab, tab[a][i], vis); } } } int main() { int x, y; cin >> n >> m; vector<int> tab[n]; bool...
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 <class U, class V> ostream& operator<<(ostream& os, const pair<U, V>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <class U, class V> istream& operator>>(istream& in, pair<U, V>& p) { in >> p.first >> p.second; return in; } lo...
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.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Cthulhu { static ArrayList<Integer>adj[]; static int dfs_num []; static int cycleLen,cnt; publ...
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> const int magicconst = 73743071; using namespace std; bool b[105]; bool c[105][105]; int n, m; void dfs(int v) { if (b[v]) return; b[v] = 1; for (int i = 0; i < (int)(n); ++i) if (c[v][i]) dfs(i); } int main() { scanf("%d%d", &n, &m); if (n != m) { printf("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<long long> adj[500]; long long vis[500]; long long ans; void dfs(long long fr, long long m) { vis[fr] = 1; for (auto it : adj[fr]) { if (it != m) { if (vis[it]) ans++; else dfs(it, fr); } } } int main() { long long 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; bool p[128][128], q[128][128]; int cnt[128], n; bool mark[128]; void dfs(int u) { if (mark[u]) return; mark[u] = true; for (int v = 1; v <= n; ++v) if (p[u][v]) dfs(v); } bool gao() { int m, a, b, i, j, t, f; scanf("%d%d", &n, &m); while (m--) { scanf("%...
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
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 vis[int(1e5 + 10)]; void bfs(vector<vector<int> > Adj, int s) { vis[s] = 1; queue<int> Q; Q.push(s); while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto v : Adj[u]) { if (vis[v] == 0) { vis[v] = 1; Q.push(v); } ...
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> const int MAXN = 110; int n, m; int f[MAXN]; int getf(int p) { return f[p] == p ? p : f[p] = getf(f[p]); } int main() { scanf("%d %d\n", &n, &m); int i, s, t; if (n == 1 || n != m) { printf("NO\n"); return 0; } for (int i = 1; i <= n; ++i) f[i] = i; int c = 0; 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
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static InputReader in; public static PrintWriter pw; public static void main(String args[]) { new Thread(null, new Runnable() { public void run() { try{ solve(); ...
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
/** * Created by ankeet on 7/20/16. */ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class B103 { static FastReader in = null; static PrintWriter out = null; st...
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.*; import java.text.*; public class Main { //SOLUTION BEGIN //Into the Hardware Mode void pre() throws Exception{} void solve(int TC) throws Exception { int N = ni(), M = ni(); int[] from = new int[M], to = new int[M]; for(int i = 0; i< M; i++)...
JAVA