This file contains hidden or 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
| class Dinic: | |
| class Edge: | |
| def __init__(self, to, cap, rev): | |
| self.to = to | |
| self.cap = cap | |
| self.rev = rev | |
| def __repr__(self): | |
| return "(to: {0} cap: {1} rev: {2})".format(self.to, self.cap, self. rev) |
This file contains hidden or 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
| class Ford_Fulkerson: | |
| class Edge: | |
| def __init__(self, to, cap, rev): | |
| self.to = to | |
| self.cap = cap | |
| self.rev = rev | |
| def __repr__(self): | |
| return "(to: {0} cap: {1} rev: {2})".format(self.to, self.cap, self. rev) |
This file contains hidden or 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
| class RootedTree: | |
| # G : adjcency list : 0 - indexed | |
| # N : the number of vertex | |
| def __init__(self,N,G): | |
| self.N = N | |
| self.G = G | |
| # for lca | |
| self.log_N = 20 |
This file contains hidden or 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
| struct rootedtree{ | |
| int V; | |
| vector<vector<int> > T; | |
| vector<vector<int> > parents; | |
| vector<int> depth; | |
| int log_N = 20; | |
| rootedtree(int N, vector<vector<int> > &Tree){ | |
| V = N; | |
| T = Tree; |
This file contains hidden or 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
| # st = SegmentTree(n, lambda a,b: a if a > b else b) | |
| class SegmentTree: | |
| def __init__(self,n,f): | |
| self.N = 1 | |
| self.f = f | |
| while(self.N < n): | |
| self.N *= 2 | |
| self.seg = [0] * (self.N * 2 -1) | |
| def update(self,k,a): |
This file contains hidden or 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
| struct edge{ | |
| int to; | |
| int cost; | |
| bool operator>(const edge &e)const{ | |
| return cost > e.cost; | |
| } | |
| bool operator<(const edge &e)const{ | |
| return cost < e.cost; |
This file contains hidden or 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
| import os | |
| nltkdata_wn = '/path/to/nltk_data/corpora/wordnet/' | |
| wn31 = "http://wordnetcode.princeton.edu/wn3.1.dict.tar.gz" | |
| if not os.path.exists(nltkdata_wn+'wn3.0'): | |
| os.mkdir(nltkdata_wn+'wn3.0') | |
| os.system('mv '+nltkdata_wn+"* "+nltkdata_wn+"wn3.0/") | |
| if not os.path.exists('wn3.1.dict.tar.gz'): | |
| os.system('wget '+wn31) | |
| os.system("tar zxf wn3.1.dict.tar.gz -C "+nltkdata_wn) |
This file contains hidden or 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 heapq import heappush, heappop | |
| def dijkstra(adjList,s): | |
| num = len(adjList) | |
| dist = [10**8 for i in range(num)] | |
| prev = [-1 for i in range(num)] | |
| queue = [] | |
| heappush(queue,(0,s)) | |
| dist[s] = 0 | |
| while len(queue) != 0: |
This file contains hidden or 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
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use Data::Dumper; | |
| use Digest::MD5 qw(md5_hex); | |
| use File::Slurp; | |
| use utf8; | |
| my @fileList = <STDIN>; | |
| shift @fileList; |
This file contains hidden or 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 pylab import * | |
| gcf().canvas.mpl_connect('key_press_event', lambda event: event.key == 'q' and close(event.canvas.figure)) |