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 <iostream> | |
template<typename T=int> | |
class edgeType{ | |
private: | |
char from; | |
char to; | |
T w; | |
public: | |
edgeType(char a, char b, int c):from(a),to(b),w(c) {} |
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
def union_find(u, arr): | |
if arr[u] == u: | |
return u | |
return union_find(arr[u], arr) | |
def union(u, v, arr): | |
arr[union_find(v, arr)] = union_find(u, arr) | |
def kruskal(nodes, edges): | |
mst = [] |
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
def prim(nodes, edges): | |
conn = {} | |
for u, v, w in edges: | |
if u not in conn: | |
conn[u] = [(w,u,v)] | |
else: | |
conn[u].append((w, u, v)) | |
if v not in conn: | |
conn[v] = [(w,v,u)] | |
else: |
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 Solution: | |
def bellman_ford(self, K, N, delay, graph, TIMEOUT): | |
delay[K-1] = 0 | |
for i in range(N): | |
for u, vs in graph.items(): | |
for v, w in vs.items(): | |
if delay[v] > delay[u] + w: | |
delay[v] = delay[u] + w | |
d = max(delay) |
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 Solution: | |
def dijkstra(self, K, N, delay, graph, TIMEOUT): | |
Q = set(range(N)) | |
delay[K-1] = 0 | |
hp = [] | |
heapq.heappush(hp, (0, K-1)) | |
while len(hp) > 0: | |
_, u = heapq.heappop(hp) | |
for v, w in graph[u].items(): | |
if delay[u] + w < delay[v]: |
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
using pairType = std::pair<int, int>; | |
using graphType = std::unordered_map<int, vector<pairType> >; | |
using heapType = std::priority_queue<pairType, vector<pairType> >; | |
class Solution { | |
private: | |
int dijkstra(const int & K, const int &N, std::vector<int> &delay, | |
graphType & graph, const int &TIMEOUT ){ | |
int d = -1; |
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
using pairType = std::pair<int, int>; | |
using graphType = std::unordered_map<int, vector<pairType> >; | |
class Solution { | |
private: | |
int bellmanFord(const int & K, const int &N, std::vector<int> &delay, | |
graphType & graph, const int &TIMEOUT ){ | |
int d = -1; | |
delay[K] = 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
import tensorflow as tf | |
import numpy as np | |
w = np.array([[3,-1,-1], [-1,5.0,-1], [1, 0 ,10]]) | |
print(w) | |
W = tf.constant(w) | |
l, u, p, q = tf.lu(W) | |
pinv = tf.matrix_inverse(p) | |
qinv = tf.matrix_inverse(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
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, |
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
op { | |
name: "Lu" | |
input_arg { | |
name: "input" | |
type_attr: "T" | |
} | |
output_arg { | |
name: "l" | |
description: "The lower triangular matrix L." |