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
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 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
from math import log | |
from collections import Counter,defaultdict | |
from functools import reduce | |
from itertools import chain | |
import Help |
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 python | |
# -*- coding: utf-8 -*- | |
from heapq import heappush, heappop | |
q = [] | |
for i in range(10**7): | |
heappush(q,[i, 10*i]) | |
while q != []: | |
x,y = heappop(q) |
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
#include "samurai.hpp" | |
#include <thread> | |
#include <signal.h> | |
Role::Role(int id, CommentedIStream& cs): id(id) { | |
int reachSize; | |
cs >> reachSize; | |
for (int k = 0; k != reachSize; k++) { | |
int x, y; | |
cs >> x >> y; |
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 UnionFind: | |
def __init__(self, N): | |
self.rank = [0]*N | |
self.par = list(range(N)) | |
def find(self, x): | |
if x != self.par[x]: | |
self.par[x] = self.find(self.par[x]) | |
return self.par[x] | |
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
local function keyCode(key, modifiers) | |
modifiers = modifiers or {} | |
return function() | |
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post() | |
hs.timer.usleep(1000) | |
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post() | |
end | |
end | |
local function keyCodeSet(keys) |
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 https://www.kaggle.com/samratp/wordbatch-ridge-fm-frtl-target-encoding-lgbm/notebook | |
class TargetEncoder: | |
# Adapted from https://www.kaggle.com/ogrellier/python-target-encoding-for-categorical-features | |
def __repr__(self): | |
return 'TargetEncoder' | |
def __init__(self, smoothing=1, min_samples_leaf=1, noise_level=0, keep_original=False, suffix='enc'): | |
self.smoothing = smoothing | |
self.min_samples_leaf = min_samples_leaf |
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 logging | |
import logging.handlers | |
import os | |
def get_logger(log_name, logdir=None, loglevel=logging.INFO): | |
_logger = logging.getLogger(log_name) | |
fmt = '%(asctime)s [%(levelname)s] %(message)s' | |
formatter = logging.Formatter(fmt) | |
if not _logger.hasHandlers(): |