graph

Distance of nearest cell having 1

别说谁变了你拦得住时间么 提交于 2021-01-29 09:50:24
问题 Given a binary matrix of size N x M. The task is to find the distance of nearest 1 in the matrix for each cell. The distance is calculated as |i1 – i2| + |j1 – j2|, where i1, j1 are the row number and column number of the current cell and i2, j2 are the row number and column number of the nearest cell having value 1. Input: The first line of input is an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of 2 lines . The first line of each test case

R: An interactive graph of a function with sliders in plotly

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 09:20:35
问题 To plot a function with its parameters being updated dynamically via sliders is easy in R using basic plot and 'manipulate' package. Here is an example of a sine wave with its amplitude and frequency being controlled by parameters A and k, respectively. library(manipulate) manipulate(plot(x, A*sin(k*x)), A = slider(1,3), k = slider(1,10)) However, the basic plot is not as pretty a plotly one. Is there a simple way to do it in plotly? Plotly provides examples of sliders on its site, but the

Adding a figure created in a function to another figure's subplot

做~自己de王妃 提交于 2021-01-29 08:27:29
问题 I created two functions that make two specific plots and returns me the respective figures: import matplotlib.pyplot as plt x = range(1,100) y = range(1,100) def my_plot_1(x,y): fig = plt.plot(x,y) return fig def my_plot_2(x,y): fig = plt.plot(x,y) return fig Now, outside of my functions, I want to create a figure with two subplots and add my function figures to it. Something like this: my_fig_1 = my_plot_1(x,y) my_fig_2 = my_plot_2(x,y) fig, fig_axes = plt.subplots(ncols=2, nrows=1) fig_axes

unique minimum spanning tree sufficient and necessary conditions

喜你入骨 提交于 2021-01-29 03:21:54
问题 Given a graph G,which are the sufficient and necessary conditions , so that this graph has a unique minimum spanning tree?In addition , how can I proove these conditions? So far , I had found that those conditions are : 1)For every partition of V(G) into two subsets, the minimum weight edge with one endpoint in each subset is unique. 2)The maximum-weight edge in any cycle of G is unique. But I am not sure if this is correct.Even in case this is correct,I cannot prove its correctness. 回答1:

Ocaml: Longest path using bfs

荒凉一梦 提交于 2021-01-29 01:49:14
问题 The problem is as follow: Given an oriented weighted graph, a start node, an end node and a number k, verify if exist a path from the start node to the end node with at least length k. This is the code i wrote and it's correct but only in specific graph. For example g1 with weights1 is as follows: let weights1 = [(2,1,1);(2,1,3);(2,1,4);(1,1,5);(5,1,2);(5,1,6);(3,1,6);(6,1,7);(4,1,3)];; let f1 = function 1 -> [5] | 2 -> [1;3;4] | 3 -> [6] | 4 -> [3] | 5 -> [2;6] | 6 -> [7] | _ -> [];; type 'a

Ocaml: Longest path using bfs

陌路散爱 提交于 2021-01-29 01:44:21
问题 The problem is as follow: Given an oriented weighted graph, a start node, an end node and a number k, verify if exist a path from the start node to the end node with at least length k. This is the code i wrote and it's correct but only in specific graph. For example g1 with weights1 is as follows: let weights1 = [(2,1,1);(2,1,3);(2,1,4);(1,1,5);(5,1,2);(5,1,6);(3,1,6);(6,1,7);(4,1,3)];; let f1 = function 1 -> [5] | 2 -> [1;3;4] | 3 -> [6] | 4 -> [3] | 5 -> [2;6] | 6 -> [7] | _ -> [];; type 'a

How to create a networkx Graph using 2D np array as input

扶醉桌前 提交于 2021-01-28 23:46:15
问题 My algorithm outputs the set of vertices describing objects in 3D space (x, y, z). In this case, there are two objects: verts = [[0.1 1. 1. ] [1. 1. 0.1] [1. 0.1 1. ] [1. 1. 1.9] [1. 1.9 1. ] [1.9 1. 1. ] [7.1 8. 8. ] [8. 8. 7.1] [8. 7.1 8. ] [8. 8. 8.9] [8. 8.9 8. ] [8.9 8. 8. ]] There are two tetrahedrons, one confined between centered on (1, 1, 1), the other on (8, 8, 8). My goal is to use breadth-first search to identify that the objects are separate, and then classify each. I have not

How to create a networkx Graph using 2D np array as input

旧城冷巷雨未停 提交于 2021-01-28 23:31:24
问题 My algorithm outputs the set of vertices describing objects in 3D space (x, y, z). In this case, there are two objects: verts = [[0.1 1. 1. ] [1. 1. 0.1] [1. 0.1 1. ] [1. 1. 1.9] [1. 1.9 1. ] [1.9 1. 1. ] [7.1 8. 8. ] [8. 8. 7.1] [8. 7.1 8. ] [8. 8. 8.9] [8. 8.9 8. ] [8.9 8. 8. ]] There are two tetrahedrons, one confined between centered on (1, 1, 1), the other on (8, 8, 8). My goal is to use breadth-first search to identify that the objects are separate, and then classify each. I have not

How to create a networkx Graph using 2D np array as input

人走茶凉 提交于 2021-01-28 22:48:17
问题 My algorithm outputs the set of vertices describing objects in 3D space (x, y, z). In this case, there are two objects: verts = [[0.1 1. 1. ] [1. 1. 0.1] [1. 0.1 1. ] [1. 1. 1.9] [1. 1.9 1. ] [1.9 1. 1. ] [7.1 8. 8. ] [8. 8. 7.1] [8. 7.1 8. ] [8. 8. 8.9] [8. 8.9 8. ] [8.9 8. 8. ]] There are two tetrahedrons, one confined between centered on (1, 1, 1), the other on (8, 8, 8). My goal is to use breadth-first search to identify that the objects are separate, and then classify each. I have not

Memory efficient way to represent shortest path?

流过昼夜 提交于 2021-01-28 19:08:57
问题 Say I am given the shortest path from node A to node B. The path is simply a list of edges, so a path A->B->C, will be represented as [(A,B),(B,C)]. Currently, each node is of type string , a path from one node to another, say (A, B), is a set of string, and the path is a list of sets. Now, the path consists of over 60k edges, and it must be saved to a database for later retrieval. So obviously, I need a very nice way to represent this path in C++ such that: the size of the path is