Skip to content

Commit

Permalink
Geppetto python
Browse files Browse the repository at this point in the history
  • Loading branch information
eavm314 committed Oct 30, 2022
1 parent 43b1afb commit cba952f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions Backtracking/Geppetto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import stdin
def readInt(): return int(stdin.readline()[:-1])
def readIntGroup(): return map(int,stdin.readline()[:-1].split())

#stdin = open('Contest1\in.txt','r')


def mezcla(ini):
#if ini == n-1: return
global ingredientes,pizzas
for i in range(ini,n):
if i!=ini:
ingredientes[i-1]=False
if i in pares and any(ingredientes[p] for p in pares[i]):
continue
pizzas+=1
ingredientes[i]=True
mezcla(i+1)

# Lectura de datos
n,m=readIntGroup()
ingredientes=[False]*n
pares = {}

for i in range(m):
a,b=readIntGroup()
a-=1
b-=1
if a>b:
if a in pares:
pares[a].append(b)
else:
pares[a]=[b]
else:
if b in pares:
pares[b].append(a)
else:
pares[b]=[a]

#Salida
pizzas=0
mezcla(0)
print(pizzas+1)
3 changes: 2 additions & 1 deletion Backtracking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ En general, la complejidad temporal de los algoritmos de este tipo llegan a ser
- [Good Morning](https://vjudge.net/problem/Kattis-goodmorning)
- [Solución](GoodMorning.cpp)
- [Geppetto](https://vjudge.net/problem/Kattis-geppetto)
- [Solución](Geppetto.cpp)
- [Solución](Geppetto.cpp) - _C++_
- [Solución](Geppetto.py) - _Python_
## Referencias
- [Recursion and Backtracking](https://www.hackerearth.com/practice/basic-programming/recursion/recursion-and-backtracking/tutorial/)
- [A tree-based introduction to backtracking](https://medium.com/swlh/a-tree-based-introduction-to-backtracking-57e38264b2d2)
Expand Down

0 comments on commit cba952f

Please sign in to comment.