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.Arrays; import java.util.LinkedList; import java.util.Scanner; public class cthulu { static Scanner scan= new Scanner(System.in); static int count = 0; static void DFS(int x,boolean visited[],LinkedList<Integer> [] list){ visited[x]=true; count++; for(int i : list[x]){ if(!visited[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
from collections import defaultdict # your code goes here v=defaultdict(list) n,m=map(int,input().split()) l=[0]*n for i in range(m): a,b=map(int,input().split()) v[a-1].append(b-1) v[b-1].append(a-1) vis=[0]*n def dfs(node): vis[node]=1 for j in v[node]: if...
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 N = 105; vector<long long int> gr[N]; long long int vis[N]; bool cycle, cycle2; void dfs(long long int cur, long long int par) { vis[cur] = 1; bool fl = 0; for (long long int x : gr[cur]) { if (vis[x] == 0) dfs(x, cur); if (vis[x] == 1 && 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
class Node: def __init__(self, n_name): """ String, list of edges -> node """ self.name = n_name self.edges = [] self.incoming_edges = [] def __str__(self): string = 'Name : ' + str(self.name) + ' \n' string += 'outcoming edges : ' + '\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.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Ktul...
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> v[1005]; bool vis[1005]; void dfs(long long s) { vis[s] = 1; for (auto i : v[s]) { if (vis[i]) continue; dfs(i); } } int main() { long long n, m, flag = 1; cin >> n >> m; for (int i = 0; i < m; i++) { long long a, b; cin >> 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
#include <bits/stdc++.h> long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return (((a * b) / gcd(a, b))); } long long phi(long long n) { long long result = n; for (long long i = 2; i * i <= n; i++) { if (n % i == 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
import java.io.*; import java.util.*; public class Main implements Runnable { edge[] aux; int m; void solve() throws IOException { //while(sc.hasNext()){ int n = sc.nextInt(); int m = sc.nextInt(); if(n<3||m<3) { ps.println("NO"); return; } edge[] edges = new edge[m]...
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 solve(); int main() { int t = 1; while (t--) solve(); return 0; } int n, m; vector<int> e[200]; bool be[200]; void dfs1(int v, int beg = -1, int end = -1) { be[v] = true; for (int i = 0; i < e[v].size(); i++) if ((v != beg || e[v][i] != end) && (v != end ...
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 B{ static boolean[] vis; static void dfs(int i) { if (vis[i]) return; vis[i] =true; for (int d = 0; d < adj[i].length; d++) { if (adj[i][d]) dfs(d); } } static boolean[][]adj; public static Reader sc = new Reader(); //public static BufferedReader br =...
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 cdr; import java.util.*; import java.math.*; import java.io.*; public class Luck{ public static InputReader sc; public static PrintWriter out; public static final int MOD = (int) (1e9 + 7); static TreeSet<Integer>[] adj; static boolean[] visited; 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
#!/usr/bin/env python import Queue n,m=[int(i) for i in raw_input().split(' ')] array = [[0 for i in range(n)] for j in range(n)] for i in range(m): x,y=[int(i)-1 for i in raw_input().split(' ')] array[x][y]=array[y][x]=1 color=[0 for i in range(n)] color[0] = 1 q = Queue.Queue() q.put(0) i=1 while(i<n and q.qsize()>...
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; bool visited[110]; bool a[110][110]; int color[110]; vector<int> v; int n; int cycle; void dfs(int u) { visited[u] = true; color[u] = 1; for (int(i) = 0; (i) < (n); (i)++) if (a[u][i + 1]) { a[u][i + 1] = a[i + 1][u] = false; if (color[i + 1] == 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
import java.util.Scanner; public class Prob104C { static int[][] adj; static int[] seen; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int M = scanner.nextInt(); if (N != M){ System.out.println("NO");return;} ...
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 Cthulhu { static boolean[][] graph; static int n, m; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); n = 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
def dfs (i): stack = [i]; seen[i] = True while (stack): i = stack[len(stack)-1] stack.pop() seen[i] = True for j in range (len(graph[i])): v = graph[i][j] if (seen[v]): continue stack.append (v) n, m = map (int, raw_input().split(' ')) graph = [[] for i in range (n)] for i in range (m): u, v...
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 = map(int, raw_input().split()) conn = [set([]) for i in range(n)] for i in xrange(m): a, b = map(int, raw_input().split()) a -= 1 b -= 1 conn[a].add(b) conn[b].add(a) ok = True queue = set([]) for i in range(n): if len(conn[i]) == 1: queue.add(i) if len(conn[i]) == 0: ok = False while que...
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> int g[110][110]; int v[110]; void dfs(int a, int n) { v[a] = 1; for (int i = 1; i <= n; i++) { if (g[a][i] && !v[i]) dfs(i, n); } } int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) g[i][j] = 0; memset(v, 0, sizeof(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; vector<vector<int> > G; vector<int> was; int cycle; void pdfs(int node, int par) { was[node]++; for (int i = 0; i < G[node].size(); i++) { int ch = G[node][i]; if (was[ch] && ch != par) cycle++; if (!was[ch]) pdfs(ch, node); } } int main() { int 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<vector<int> > ar(110, vector<int>(110, 0)); vector<vector<int> > te(110, vector<int>(110, 0)); int ar1[110]; int flag[110]; int n1; bool f; void dfs(int n) { int i; ar1[n] = 1; flag[n] = 1; for (i = 1; i <= n1; i++) { if (ar[n][i] == 1 && flag[i] == 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
#include <bits/stdc++.h> using namespace std; vector<int> adjList[110]; int state[110]; int parent[110]; int qtyCycles; void dfs(int u) { state[u] = 0; for (int v : adjList[u]) { if (state[v] == -1) { parent[v] = u; dfs(v); } else if (state[v] == 0 && v != parent[u]) { qtyCycles++; } ...
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 Main{ static Scanner sc=new Scanner(System.in); static int n=sc.nextInt(); static int m=sc.nextInt(); static int f[]=new int[n+1];//n个节点 的数组 public static void main(String[] args) { int flag=0; init(); flag=merge(flag); // flag=check(); if(m!=n){ System.out.p...
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[101]; vector<vector<int>> adj; void dfs(int s) { vis[s] = 1; for (int i = 0; i < adj[s].size(); i++) if (!vis[adj[s][i]]) dfs(adj[s][i]); } int main() { int n, m; cin >> n >> m; if (m != n) { cout << "NO\n"; return 0; } adj.resize(n + 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
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
import java.util.Scanner; public class B_Cthulhu { static boolean[] vis; static int cnt =0; // do dfs and count number of reached nodes static void isconnected (boolean[][] g,int i){ // mark as visited vis[i] = true; cnt++; //for (int j=0;j<vis.length;j++) System.out.pri...
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 = 101; int n, m, c, par[N]; int get_par(int u) { return u == par[u] ? u : par[u] = get_par(par[u]); } bool uni(int u, int v) { u = get_par(u); v = get_par(v); if (u == v) return 0; par[u] = v; c--; return 1; } int main() { iota(par, par + N, 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; int n, m, i, x, y, s; vector<int> a[105]; bool c[105]; void dfs(int i) { c[i] = true; s++; for (int j = 0; j < a[i].size(); j++) { if (!c[a[i][j]]) dfs(a[i][j]); } } int main() { cin >> n >> m; for (i = 0; i < m; i++) { cin >> x >> y; a[x].push_back(...
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.io.PrintWriter; import static java.lang.Math.*; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; /** * * @author pttrung */ public class C { public static double Epsilon = 1e-6; public ...
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.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.Link...
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
par,vis = [],[] def dfs(u, prev): if par[u]: # print ' CCC', u+1 return 1 if vis[u]: return 0 vis[u] = True # print ' ', u + 1 r = 0 for v in adj[u]: if v != prev: par[u] = True r += dfs(v, u) par[u] = False # print ' --',...
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 size[205]; int arr[205]; int root(int i) { while (i != arr[i]) { arr[i] = arr[arr[i]]; i = arr[i]; } return i; } void unionn(int A, int B) { int root_A = root(A); int root_B = root(B); if (size[root_A] < size[root_B]) { arr[root_A] = arr[root_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.*; import java.io.*; public class Problems { private static boolean marked[] ; private static int left ,cycled ; static class Graph { private ArrayList<Integer> v[] ; public Graph (int size ){ v = new ArrayList [size] ; ...
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 = 1e3 + 5; int p[105], s[105]; int fnd(int a) { return a == p[a] ? a : p[a] = fnd(p[a]); } void unn(int a, int b) { a = fnd(a); b = fnd(b); if (s[a] < s[b]) swap(a, b); s[a] += s[b]; p[b] = a; } int main() { int n, m, u, v; scanf("%d %d", &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; const int Max = 110; vector<int> adj[Max]; void init(int n) { int i; for (i = 1; i <= n; i++) adj[i].clear(); } int vis[Max]; int ans; int s; void dfs(int i, int lev) { vis[i] = 1; int j, len = adj[i].size(); for (j = 0; j < len; j++) { int v = adj[i][j]; ...
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.*; public class Main { public static void main(String args[]) throws Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStr...
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 unionSet(u,v): up = findSet(u) vp = findSet(v) if up == vp: return else: parent[up] = vp # cnt[vp] += cnt[up] def findSet(u): if parent[u] != u: parent[u] = findSet(parent[u]) return parent[u] n,m = map(int,input().split()) if n != m: print('NO') ex...
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 sys def todos_visitados(list): return len(list) == sum(list) def um_componente(vertices, n): vizinhos = [0] visitado = [False] * n while len(vizinhos) != 0: v = vizinhos.pop() visitado[v] = True for u in vertices[v]: if not visitado[u]: vi...
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 g[102][102]; bool used[102]; int n, m, a, b; bool cycle; int dfs(int cur, int par = -1) { used[cur] = true; int ret = 1; for (int i = 0; i < n; i++) if (g[cur][i] && i != par) { if (!used[i]) ret += dfs(i, cur); else { a = cur; ...
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
/* The basic idea is to construct the graph and using dfs to find a cycle in the graph as at most two edges between two nodes, so if there is a cycle, it must be equal or bigger than 3 modified we first check if the nubmer of node equals the number of edges if not, say no, we can find that if it is a cthulhu, the num...
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 findSet(u): if parents[u] != u: parents[u] = findSet(parents[u]) return parents[u] def unionSet(u, v): up = findSet(u) vp = findSet(v) if up == vp: return True global count_p count_p -= 1 if ranks[up] > ranks[vp]: parents[vp] = up elif ranks[up] < ranks[vp]: parents[up] = vp ...
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 = raw_input() ar = n.split() arr = [ int(s) for s in ar ] gr = range(arr[0]) pr = range(arr[0]) am = range(arr[0]) for i in range(0,arr[0]): gr[i] = [] am[i] = 0 pr[i] = -1; for i in range(0, arr[1]): n = raw_input() ar = n.split() t = [ int(s)-1 for s in ar ] gr[t[0]].append(t[1]) gr[t[1]].ap...
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 f(): n, m = map(int, input().split()) t = [[] for i in range(n + 1)] p = [0] * (n + 1) for i in range(m): a, b = map(int, input().split()) t[a].append(b) t[b].append(a) p = [a for a in range(1, n + 1) if len(t[a]) == 1] if any(len(i) == 0 for i in t[1: ]): return 'NO'...
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(node): cnt = 1 visited[node] = True for adj in graph[node]: if not visited[adj]: cnt += dfs(adj) return cnt n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] visited = [False]*(n+1) if m != n: print("NO") else: for _ in range(m): a, b = ...
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 MaxSize = 1e2 + 5; using namespace std; int n, m; bool Edge[MaxSize][MaxSize]; bool Node[MaxSize]; void DFS(int cur) { if (Node[cur]) return; Node[cur] = 1; for (long long i = 1; i < n + 1; i++) if (Edge[i][cur]) DFS(i); } int main() { ios_base::sync_with_stdio(0); cin.t...
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; list<int> adj[101]; int m, n, x, y, cnt; bool visited[101]; void dfs(int u) { visited[u] = true; ++cnt; for (list<int>::iterator it = adj[u].begin(); it != adj[u].end(); ++it) if (!visited[*it]) dfs(*it); } int main() { scanf("%d %d\n", &n, &m); for (int i = 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
#include <bits/stdc++.h> using namespace std; bool was[101]; vector<int> G[101]; void dfs(int u) { was[u] = true; for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (!was[v]) dfs(v); } } int main() { int n, m; cin >> n >> m; bool res = true; for (int i = 0; i < m; i++) { int 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.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner r = new Scanner(System.in); N = r.nextInt(); M = r.nextInt(); g = new ArrayList[N]; for(int i = 0; i < N; i++) g[i] = 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
n, m = [int(i) for i in input().split()] g = [[] for i in range(n)] mark = [False] * n if n is not m: print("NO") else: def dfs(node): mark[node] = True for u in g[node]: if mark[u] is False: dfs(u) for i in range(m): v, u = [int(x)-1 for x in input().spli...
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; vector<vector<int> > arr(120); bool vis[120] = {false}; void dfs(int node) { if (vis[node]) { return; } vis[node] = true; for (int i = 0; i < arr[node].size(); i++) { dfs(arr[node][i]); } return; } int main() { int n, m; cin >> n >> m; if (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
def dfs(u): vis[u]=1 for v in adj[u]: if vis[v]==0: dfs(v) n,m=map(int,input().split()) vis=[0]*n adj=[[] for w in range(n)] for i in range (m): u,v = map(int,input().split()) u-=1 v-=1 adj[u].append(v) adj[v].append(u) cnt=0 for i in range(0,n-1): if vis[i]==0: dfs(i) cnt+=1 if cnt==1 and 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
#include <bits/stdc++.h> using namespace std; int n, m, vis[104]; vector<int> adj[104]; void dfs(int s) { vis[s] = 1; for (int v : adj[s]) { if (!vis[v]) { dfs(v); } } } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[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
def dfs (num,av): global res; b.add(num) for v in g[num]: if v!=av: if v in b: res += 1; g[v].remove(num) else:b.add(v); dfs(v,num) n,m = map (int,input().split()) g,b,res = [[] for _ in range(n)], set(),0 for _ in range(m): u,v = map(int,input().split()) g[u-1].append(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
#include <bits/stdc++.h> using namespace std; int n, m, cnt = 0; int dat[105][105]; bool vis[105]; void dfs(int x) { vis[x] = true; cnt++; for (int i = 1; i <= n; i++) if (!vis[i] && dat[x][i] == 1) dfs(i); } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; da...
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 = 110; int n, m; int fa[N]; bool ans, ansf = true; int find(int x) { if (fa[x] != x) fa[x] = find(fa[x]); return fa[x]; } void unionn(int x, int y) { fa[y] = x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for...
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 PrG { public static void dfs(int k,boolean[]vis,int n,boolean[][]adjmatrix){ vis[k]=true; for (int i = 1; i <=n; i++) { if(adjmatrix[i][k]&&!vis[i]){ dfs(i,vis,n,adjmatrix); } } } public static void main(String[] args){ Scanner input = new Scanner(System...
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.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.util.Set; public class P103B { public static void main(String[] args) { Scanner inScanner = new Scanner(System.in); int n = inScanner.nextInt(); int m = inScanner.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; const char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}; const int dy[] = {1, 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
def dfs(graph, start): visited[start] = True for i in graph[start]: if not visited[i]: dfs(graph, i) a, b = list(map(int, input().split(' '))) g = {} for i in range(1, a+1): g[i] = [] for i in range(b): x, y = map(int, input().split(' ')) g[x].append(y) g[y].append(x) vis...
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 const N = 3112; int const INF = 1e9 + 7; int n, m; vector<int> g[N]; int used[N]; int cnt; void dfs(int v) { used[v] = true; for (int c = 0; c < g[v].size(); c++) { if (!used[g[v][c]]) dfs(g[v][c]); } } int main() { int x, y; cin >> n >> m; if (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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Stack; import java.util.StringTokenizer; public class Solution { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; pr...
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 { ArrayList<ArrayList<Integer>>graph ; boolean[] v ; int cycles ; public static void main(String[] args) { new Main().start(); } private void start() { Scanner r = new Scanner(System.in); 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.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Cthulhu_B103 { static ArrayList<Integer>[] adjList; static boolean[] visited; static boolean[] recStack; static void dfs(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
import java.io.*; import java.util.*; import java.math.*; public class Main { int n, m; List<List<Integer>> adjList = new ArrayList<>(); int[] visited; int node1 = -1; int node2 = -1; int cnt = 0; public void solve() throws IOException{ n = in.nextInt(); m = 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; const int N = 511111; int mm[105][105]; bool vis[1005]; int m, n; void dfs(int u) { vis[u] = 1; for (int i = 1; i <= n; i++) { if (vis[i] == 0 && mm[u][i] == 1) dfs(i); } } int main() { while (~scanf("%d%d", &n, &m)) { int i; for (i = 0; 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
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000; vector<int> g[MAX_N + 10]; vector<int> dfs_trace; bool is_circle[MAX_N + 10] = {0}; int circles_finded = 0; int b[MAX_N + 10] = {0}; void scanGraph(int m) { int x; int y; for (int i = 0; i < m; ++i) { scanf("%d %d", &x, &y); g[x].push_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.*; import java.io.*; public class special { static int circle = 0; static void dfs(int i , int[][] edges, int[] visited,int n) { if(visited[i]==1){ circle++; return; } visited[i]=1; for(int j=0;j<n;j++){ if(edges[j][i] == 1) { edges[i][j]=0; dfs(j,edges,visited,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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { static int i, j, k, n, m, t, y, x, sum=0; static long mod = 998244353; static FastScanner fs = new FastScanner(); static PrintWriter out = 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> using namespace std; vector<vector<int>> g; vector<bool> used; vector<int> cycle; vector<int> p; bool find_cycle(int v, int pr) { p[v] = pr; used[v] = 1; for (int i : g[v]) { if (used[i] && i != pr) { while (v != i) { cycle.push_back(v); if (v == -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
#include <bits/stdc++.h> using namespace std; const int N = 110; int p[N]; vector<int> adj[N], roots; int n, m; bool vis[N], root[N]; int S = 0, E = 0, cnt = 0; void store(int u) { while (1) { root[u] = 1; roots.push_back(u); if (u == E) return; u = p[u]; } } void dfs(int u) { vis[u] = 1; for (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
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int MAX = 1e18, MIN = -1e18, MOD = 1000000...
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 cycle_vertex(int v, vector<vector<int>>& g, vector<bool>& used, vector<int>& p) { if (used[v]) retur...
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 fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } vector<int> a[101]; vector<int> vis(101); void DFS(int s) { vis[s] = 1; for (int i = 0; i < a[s].size(); i++) { int u = a[s][i]; if (!vis[u]) { DFS(u); } } } int main() { int 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
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
import java.awt.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class C { static LinkedList<Integer>[] edges; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 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
#include <bits/stdc++.h> using namespace std; const int inf = 100010; const int MOD = 1000000007; const double pi = acos(-1.0); int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int lcm(int a, int b) { return (a * (b / gcd(a, b))); } int fx[] = {0, 0, 1, -1}; int fy[] = {-1, 1, 0, 0}; int n, m; int flg = 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; int n, m; const int mxN = 1e4; vector<vector<int> > edges(mxN); vector<vector<int> > cycles(mxN); int cyclenumber; vector<int> color(mxN); vector<int> mark(mxN); vector<int> par(mxN); void dfs(int node, int p) { if (color[node] == 2) { return; } if (color[node] ==...
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.*; public class Main extends PrintWriter { private final InputStream stream = System.in; private final byte[] bytes = new byte[IN_BUFF_SIZE]; private int pos = 0; private int len = -1; public Main() throws FileNotFoundException { super(new BufferedOutputStream(System.out, ...
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> v[105]; int vis[105], cunt = 0, par[105]; void graphcheck(int root) { vis[root] = -1; for (auto u : v[root]) { if (!vis[u]) { par[u] = root; graphcheck(u); } else if (vis[u] == -1) { if (par[root] != u) ++cunt; } } vis[root]...
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.*; public class Main { // Graph modeled as list of edges static int[][] graph; static List<int[]> cycles = new ArrayList<int[]>(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(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
n, m = map(int, input().split()) if n < 3 or n != m: # minimo 3 vertices para un circulo print("NO") # todo vertice debe tener un edge 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().sp...
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.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; public class Contest80_2 { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 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
class UnionFind: def __init__(self, n): self.parent = [i for i in range(n)] self.rank = [0 for i in range(n)] def union(self, u, v): up = self.find(u) vp = self.find(v) if up == vp: return if self.rank[up] == self.rank[vp]: self.parent[up] = vp self.rank[vp] += 1 ...
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 Cthulhu { static class Pair<E> { final E first, second; Pair(E first, E second) { this.first = first; this.second = second; } } static List<Integer> cycle(int size, Map<Integer, List<Integer>> edges) { ...
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.List; import java.util.Collections; import java.util.InputMismatchException; import java.math.BigInteger; import java.io.*; /** * Generated by Contest helper plug-in * Actual solution is at the bottom */ public class Main { public static void main(String[] args) { Inp...
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()) lst = [[] for i in range(n +1)] for i in range(m): x , y = map(int, input().split()) lst[x].append(y) lst[y].append(x) #print(lst) a = [0]*(n+1) b = [0]*(n+1) c = 0 def func(n): global a, b, c, lst a[n] = 1 for j in lst[n]: if a[j] == 1 and b[n] != j:...
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.Scanner; /** * Created by user on 2017-03-31. * cycle 찾기 */ public class CodeForce103B { static boolean[][] table = new boolean[101][101]; static boolean[] visit = new boolean[101]; static int n, m, x, y, count = 0; public static void main(String [] args) { Scanner sc = 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 java.io.*; import java.util.*; public class B { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; int fnd(int v, int[] p) { return (v == p[v]) ? v : (p[v] = fnd(p[v], p)); } boolean uni(int v1, int v2, int[] p) { v1 = fnd(v1, p); ...
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 cycle = 0; bool single = true; struct graph { vector<int> adj; bool isBlack; graph(void) { isBlack = false; } }; void dfs(graph G[], int index, int CB); int main(void) { int n, m; graph G[106]; cin >> n >> m; for (int i = 0; i < m; i++) { int 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.util.Scanner; public class Problem80C { static boolean[][] match; static boolean[] visited; static int n; public static void dfs(int v) { visited[v] = true; for (int i = 0; i < n; i++) { if(match[v][i] && !visited[i]) { dfs(i); } } } 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; int nro_ciclos = 0; void DFS(vector<pair<int, vector<int>>> &graph, int a, int b) { if (graph[a].first == 0) { graph[a].first = 1; for (int i = 0; i < graph[a].second.size(); ++i) { if (graph[graph[a].second[i]].first == 1 && graph[a].second[i] != 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.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Smile { static Scanner in; static PrintWriter out; static int[] used; static ArrayList<Integer>[] list; static int count1; static int count2; static void dfs(int v, ...
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 __future__ import print_function import sys from collections import * from heapq import * from functools import * import re from itertools import * INF=float("inf") NINF=float("-inf") try: input=raw_input except: pass def read_string(): return input() def read_string_line(): return [x for x in ...
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; using namespace std; bool color[50000]; int par[50000]; int find(int a) { if (par[a] == a) return a; return par[a] = find(par[a]); } void Union(int a, int b) { if (find(a) != find(b)) par[find(b)] = find(a); } int main() { int n, m; cin >> n >> m; for (int i = 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
n,m=map(int,input().split()) a=[[] for _ in range(n+1)] vis=[] for _ in range(m): x,y=map(int,input().split()) a[x].append(y) a[y].append(x) def dfs(x): vis.append(x) for z in a[x]: if not(z in vis): dfs(z) dfs(1) if n<3 or n!=m or len(vis)!=n: print("NO") else: print("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
#include <bits/stdc++.h> using namespace std; int maxi = 102; vector<vector<int>> mat(maxi, vector<int>(maxi, 0)); vector<int> vis(maxi, 0); int visitados = 0; void dfs(int v, int n) { vis[v] = 1; visitados++; for (int i = 1; i < n + 1; i++) { if (vis[i]) { continue; } else { if (mat[v][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; vector<vector<int>> adjList; bool visited[100]; void dfs(int node) { if (visited[node]) return; visited[node] = true; for (int i = 0; i < adjList[node].size(); i++) dfs(adjList[node][i]); } int main() { int nodes, vertices; cin >> nodes >> vertices; adjList = 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
from collections import defaultdict from typing import List, Tuple def solve(n: int, m: int, adj: List[Tuple[int, int]]) -> str: visited = [0] * n graph = defaultdict(list) # type: Dict[int, List[int]] for u, v in adj: graph[u - 1].append(v - 1) graph[v - 1].append(u - 1) stack = [0] ...
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 MAXN = 100; int n, m; struct vertex { int parent; bool mark; vector<int> adj; } v[MAXN]; inline void INPUT() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; v[a].adj.push_back(b); v[b].adj.push_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
import java.util.LinkedList; import java.util.Scanner; public class p103b { static boolean [] visit; static LinkedList<Integer>[]q; public static void dfs(int now) { if(visit[now]) return; visit[now] = true; while(!q[now].isEmpty()) { dfs(q[now].remove()); ...
JAVA