This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Node(object): | |
def __init__(self, key, value): | |
self.key = key | |
self.value = value | |
self.prev = None | |
self.next = None | |
class LRUCache(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample input: | |
# First line has two integers N, denoting the number of nodes in the graph and M, denoting the number of edges in the graph. | |
# The next M lines each consist of three space separated integers x y r, where x and y denote the two nodes between which the undirected edge exists, r denotes the weight of edge between the corresponding nodes. | |
# 4 6 | |
# 1 2 5 | |
# 1 3 3 | |
# 4 1 6 | |
# 2 4 7 |