adj

模板

雨燕双飞 提交于 2019-12-04 04:40:26
矩阵 矩乘(现在正确, 20191021) const LL MOD = 1e9 + 7; struct Matrix { int row, col; LL val[33][33]; void init0() { memset(val, 0, sizeof val); } void init1() { memset(val, 0, sizeof val); for (int i = 0; i < row; ++ i) val[i][i] = 1; } Matrix () {} Matrix (int _row, int _col) { row = _row; col = _col; memset(val, 0, sizeof val); } Matrix operator * (const Matrix B) const { Matrix C (row, B.col); for (int i = 0; i < row; ++ i) for (int j = 0; j < B.col; ++ j) for (int k = 0; k < col; ++ k) (C.val[i][j] += val[i][k] * B.val[k][j] % MOD) %= MOD/*, printf("%d%d += %lld * %lld\n", i, j, val[i][k], val[k][j

AcWing 345. 牛站 Cow Relays

和自甴很熟 提交于 2019-12-04 04:37:44
由于我太菜了,不会矩阵乘法,所以给同样不会矩阵乘法同学的福利 首先发现这题点很多边很少,实际上有用的点 \(<= 2 * T\) (因为每条边会触及两个点嘛) 所以我们可以把点的范围缩到 \(2 * T\) 来,然后... Bellman - Ford \(O(NT)\) 什么,限制边数?那不就是可爱的 \(BellmanFord\) 吗? 看看复杂度,嗯嗯 \(10 ^ 8\) 海星,常数超小的我肯定不用吸氧的 #pragma GCC optimize(2) #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> using namespace std; const int N = 205, M = 105; struct Edge{ int u, v, w; }e[M]; int m, n, s, t, adj[N], dis[N], bDis[N], tot; void inline read(int &x) { x = 0; char s = getchar(); while(s > '9' || s < '0') s = getchar(); while(s <= '9' && s >= '0') x = x * 10 + s - '0',

Optimizing dict of set of tuple of ints with Numba?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am learning how to use Numba (while I am already fairly familiar with Cython). How should I go about speeding up this code? Notice the function returns a dict of sets of two-tuples of ints. I am using IPython notebook. I would prefer Numba over Cython. @autojit def generateadj(width,height): adj = {} for y in range(height): for x in range(width): s = set() if x>0: s.add((x-1,y)) if x<width-1: s.add((x+1,y)) if y>0: s.add((x,y-1)) if y<height-1: s.add((x,y+1)) adj[x,y] = s return adj I managed to write this in Cython but I had to give up on