bipartite_dfs(graph, node, 1 - alternator, visited) return colors problem = GCJManager(6234486, 0, 0) # Main per-case logic goes here: for case in range(int(problem.input())): # Begin each case by setting up a graph implemented as a dictionary. pairs = list() names = set() league_graph = dict() for line in range(int(problem.input())): pair = problem.input().split() pairs.append(pair) names.add(pair[0]) names.add(pair[1]) for name in names: league_graph[name] = set() for pair in pairs: league_graph[pair[0]].add(pair[1]) league_graph[pair[1]].add(pair[0]) # Graph is initialized. Now check whether it is bipartite or not. colors = bipartite_dfs(league_graph, pairs[0][0], 0) if colors[0].intersection(colors[1]) == set(): problem.output('Yes') else: problem.output('No') msg = problem.finish() print(msg)
""" Author: Jeff Sell Solution to Google Code Challenge practice problem "Store Credit" https://code.google.com/codejam/contest/351101/dashboard#s=p0 This solution makes use of GCJManager. https://github.com/jtsell/GCJManager """ from gcjmanager import GCJManager from pairing import Pairing problem = GCJManager(351101, 0, 0) for case in range(0, int(problem.input())): Credit = problem.input() Items = problem.input() Prices = problem.input() myPairing = Pairing(Credit, Items, Prices) answer = myPairing.getPair() problem.output('{} {}'.format(answer[0], answer[1])) message = problem.finish() print(message)
""" Author: Jeff Sell Solution to Google Code Challenge "Captain Hammer" https://code.google.com/codejam/contest/6234486/dashboard#s=p1 Makes use of GCJManager, available at: https://github.com/jtsell/GCJManager """ from gcjmanager import GCJManager from math import asin, pi problem = GCJManager(6234486, 1, 0) g = 9.8 for case in range(int(problem.input())): v, d = problem.input().split() v = int(v) d = int(d) # Ugly hack to resolve floating point imprecision causing domain error: x = (d * g) / v ** 2 if x > 1: x = 1 # /Ugly hack. theta = asin(x) * (90 / pi) problem.output(str(theta)) msg = problem.finish() print(msg)