def tarjanSCC(F):  #set stack size to needed lim
     srl(100000)
     F.L = {i: INF
            for i in F.AL1}
     F.N = {i: INF
            for i in F.AL1}
     F.STK = []
     F.vis = set()
     F.SCC = []
     F.nc = 0
     for v in F.AL1:
         if F.N[v] == INF: F.tarjan_help(v)
예제 #2
0
#Set up environment
import urllib
import pandas as pd
from bs4 import BeautifulSoup
from sys import setrecursionlimit as srl
srl(500000)

#Make sure to change which df you are reading each time a new chunk is run
sdwis=pd.read_csv('df9.csv')
#function takes an index from the dataframe of water treatment plants
#uses that index to find the wid and link to page on violations
#creats two dataframes of health violations and reporting violations
def viodata(index):
    #creating the soup and gathering wid
    wid=sdwis.wid[index]
    url ='https:' + sdwis.links[index]
    page=urllib.urlopen(url).read()
    soup = BeautifulSoup(page, "html.parser")

    #goes into the page and finds the tables of health and reporting violations
    allhvio=[]
    allmrvio=[]
    for table in soup.findAll('table', {'class':'result2'}):
        count=0
        for item in table.findAll('th'):
            count+=1
        if count == 6: #checks if table is a health violation
            hvio=[wid]
            for item in table.findAll('td'):
                hvio.append(item.renderContents()) #builds a list of all data for that violation
            allhvio.append(hvio) #builds list of lists of all violations and their data
예제 #3
0
    ekor = kepala
    for data in arr[1:]:
        ekor.next = Simpul(data)
        ekor = ekor.next
    return kepala


def printll(kepala):
    while kepala:
        print(kepala.data, end=' ')
        kepala = kepala.next
    print()


from sys import setrecursionlimit as srl
srl(10000)
arr = list(int(i) for i in input().strip().split(' '))
l = ll(arr[:-1])
r = reverse(l)
printll(r)

#Titik tengah LL
"""
Input 1 :
1 2 3 4 5 -1
Output 1 :
3

Input 2 :
1 2 3 4 -1
Output 2 :
예제 #4
0
def ll(arr):

    if arr == []:
        return None

    kepala = Simpul(arr[0])
    ekor = kepala

    for data in arr[1:]:
        ekor.next = Simpul(data)
        ekor = ekor.next

    return kepala

from sys import setrecursionlimit as srl
srl(11000)

arr = list(int(i) for i in input().strip().split(' '))
l = ll(arr[:-1])
panjangnya = cariPanjang(l)
print(panjangnya)


#Print ith Simpul
"""
Input 1 :
1
3 4 5 2 6 1 9 -1
3
Output 1 :
2
예제 #5
0
from sys import setrecursionlimit as srl
srl(2 * 10**6)


class Node:
    def __init__(self):
        self.cnt = 0
        self.children = {}


def parse():
    N, K = input().strip().split()
    N, K = int(N), int(K)
    strings = [input().strip() for _ in range(N)]
    return N, K, strings


def solve(N, K, strings):
    root = Node()
    for s in strings:
        curr = root
        for ch in s:
            if ch not in curr.children:
                curr.children[ch] = Node()
            curr = curr.children[ch]
        curr.cnt += 1

    def dfs(root, depth=0):
        ans = 0
        if root.children:
            for ch in root.children:
예제 #6
0
from fractions import gcd
from sys import setrecursionlimit as srl
from functools import wraps
srl(10**6)

CACHE = {}
rhave, right, mod = None, None, 10**9 + 7


def cache(fn):
    @wraps(fn)
    def cached(have, nxt):
        key = (have, nxt)
        global CACHE
        if key not in CACHE:
            CACHE[key] = fn(*key)
        return CACHE[key]

    return cached


@cache
def rsolve(have, nxt):
    print "have: %s" % (have, )
    print "nxt: %s" % (nxt, )
    need = k / have

    if nxt == n:
        return 1 if need == 1 else 0
    elif need == 1:
        return right[nxt] if nxt != n else 1
예제 #7
0
from sys import setrecursionlimit as srl

input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log

mi = lambda: map(int, input().split())
ii = lambda: int(input())
li = lambda: list(map(int, input().split()))
mati = lambda r: [li() for _ in range(r)]
lcm = lambda a, b: (a * b) // gcd(a, b)
srl(10**4)

MOD = 10**9 + 7


def dfs(arr, node, cnt):
    temp = 1
    new = []
    for x in arr[node]:
        if x != cnt:
            new.append(dfs(arr, x, node))
    try:
        new.sort(reverse=True)
    except:
        pass
    for x in range(len(new)):
예제 #8
0
En el caso de muestra # 2, el Dr. Patel necesita elegir P = 3 platos:
     Puede elegir las 2 mejores placas de la primera pila (80 + 80 = 160).
     No puede recoger platos de la segunda pila.
     Puede elegir el plato superior de la tercera pila (20).
En total, la suma de los valores de belleza es 180.

Muy parecido al problema de Knapsack pero con algo de complejidad extra
https://en.wikipedia.org/wiki/Knapsack_problem#0-1_knapsack_problem

Este problema probablemente es el mas confuso de explicar

"""
#Establezco el limite de llamadas recursivas
from sys import setrecursionlimit as srl
srl(10**5)

#Una solucion optima es usar Programacion dinamica, es decir dividir el problema en subproblemas mas pequeños


#la funcion resolver necesita los valores n (la cantidad de pilas de platos), k (la cantidad de platos en cada pila), p (la cantidad de platos a tomar) y a (la lista de listas que contien todos los valores de los platos)
def resolver(n, k, p, a):
    #Nuestro primer subproblema es resolver la suma de cada plato hasta i, ya que si el Dr.Patel decide tomar el cuarto plato debe de tomar los primeros 3
    #es decir debemos de saber la suma de la belleza de cada plato hasta cada elemento i
    sumas = []
    #por cada fila de platos en la lista de listas de los platos
    for fila in a:
        #una lista temporal para guardar la suma
        s = [0]
        #por cada plato en la fila
        for x in fila: