Editing
2016 Dec Gold Problem 1 Moocast
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Python === <pre> from collections import defaultdict class Cow: def __init__(self, i, x, y): self.i = i self.x = x self.y = y def dfs(graph, visited, node, val): if visited[node]: return visited[node] = True for edge in graph[node]: if visited[edge[0]]: continue if edge[1] <= val: dfs(graph, visited, edge[0], val) def reach(graph, total, val): visited = [False] * total dfs(graph, visited, 0, val) return sum(visited) >= total def main(): with open('moocast.in', 'r') as fin: n = int(fin.readline().strip()) cows = [Cow(i, *map(int, line.split())) for i, line in enumerate(fin)] min_distance = 625000000 * 2 max_distance = 0 graph = defaultdict(list) for cow in cows: for cow1 in cows: if cow.i == cow1.i: continue d = (cow1.x - cow.x)**2 + (cow1.y - cow.y)**2 min_distance = min(d, min_distance) max_distance = max(d, max_distance) graph[cow.i].append((cow1.i, d)) while min_distance < max_distance: mid = (min_distance + max_distance) // 2 if reach(graph, n, mid): max_distance = mid else: min_distance = mid + 1 with open('moocast.out', 'w') as fout: fout.write(str(max_distance) + '\n') if __name__ == "__main__": main() </pre>
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information