undirected-graph-typed 2.4.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/cjs/index.cjs.map +1 -1
  2. package/dist/cjs-legacy/index.cjs.map +1 -1
  3. package/dist/esm/index.mjs.map +1 -1
  4. package/dist/esm-legacy/index.mjs.map +1 -1
  5. package/dist/types/data-structures/base/linear-base.d.ts +6 -6
  6. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -6
  7. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -1
  8. package/dist/types/data-structures/binary-tree/index.d.ts +3 -3
  9. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +150 -20
  10. package/dist/types/data-structures/binary-tree/tree-map.d.ts +188 -0
  11. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +238 -147
  12. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +270 -0
  13. package/dist/types/data-structures/binary-tree/tree-set.d.ts +181 -0
  14. package/dist/types/interfaces/binary-tree.d.ts +2 -2
  15. package/dist/types/types/data-structures/binary-tree/index.d.ts +3 -3
  16. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +33 -0
  17. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +16 -0
  18. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +33 -0
  19. package/dist/umd/undirected-graph-typed.js.map +1 -1
  20. package/dist/umd/undirected-graph-typed.min.js +1 -1
  21. package/dist/umd/undirected-graph-typed.min.js.map +1 -1
  22. package/package.json +2 -2
  23. package/src/data-structures/base/linear-base.ts +2 -12
  24. package/src/data-structures/binary-tree/avl-tree.ts +1 -1
  25. package/src/data-structures/binary-tree/binary-tree.ts +45 -21
  26. package/src/data-structures/binary-tree/bst.ts +85 -10
  27. package/src/data-structures/binary-tree/index.ts +3 -3
  28. package/src/data-structures/binary-tree/red-black-tree.ts +568 -76
  29. package/src/data-structures/binary-tree/tree-map.ts +439 -0
  30. package/src/data-structures/binary-tree/tree-multi-map.ts +488 -325
  31. package/src/data-structures/binary-tree/tree-multi-set.ts +502 -0
  32. package/src/data-structures/binary-tree/tree-set.ts +407 -0
  33. package/src/data-structures/queue/deque.ts +10 -0
  34. package/src/data-structures/trie/trie.ts +6 -8
  35. package/src/interfaces/binary-tree.ts +2 -2
  36. package/src/types/data-structures/binary-tree/index.ts +3 -3
  37. package/src/types/data-structures/binary-tree/tree-map.ts +45 -0
  38. package/src/types/data-structures/binary-tree/tree-multi-set.ts +19 -0
  39. package/src/types/data-structures/binary-tree/tree-set.ts +39 -0
  40. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -236
  41. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -197
  42. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +0 -243
  43. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
  44. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
  45. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
  46. package/src/data-structures/binary-tree/avl-tree-counter.ts +0 -539
  47. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +0 -438
  48. package/src/data-structures/binary-tree/tree-counter.ts +0 -575
  49. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +0 -3
  50. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +0 -3
  51. package/src/types/data-structures/binary-tree/tree-counter.ts +0 -3
@@ -1,4 +1,4 @@
1
- "use strict";var undirectedGraphTyped=(()=>{var I=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var W=(d,a,e)=>a in d?I(d,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[a]=e;var Q=(d,a)=>{for(var e in a)I(d,e,{get:a[e],enumerable:!0})},X=(d,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of P(a))!B.call(d,n)&&n!==e&&I(d,n,{get:()=>a[n],enumerable:!(t=G(a,n))||t.enumerable});return d};var q=d=>X(I({},"__esModule",{value:!0}),d);var V=(d,a,e)=>W(d,typeof a!="symbol"?a+"":a,e);var J={};Q(J,{DFSOperation:()=>z,Range:()=>D,UndirectedEdge:()=>S,UndirectedGraph:()=>H,UndirectedVertex:()=>F});var j=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(d){let a=Math.random()*16|0;return(d=="x"?a:a&3|8).toString(16)})},U=function(d,a){let e=-1,t=d?d.length:0,n=[];for(;++e<t;){let r=d[e];a(r,e,d)&&(n.push(r),Array.prototype.splice.call(d,e--,1),t--)}return n};var N=class{*[Symbol.iterator](...a){yield*this._getIterator(...a)}*entries(){for(let a of this)yield a}*keys(){for(let a of this)yield a[0]}*values(){for(let a of this)yield a[1]}every(a,e){let t=0;for(let n of this)if(!a.call(e,n[1],n[0],t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(a.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this){let[r,s]=n;a.call(e,s,r,t++,this)}}find(a,e){let t=0;for(let n of this){let[r,s]=n;if(a.call(e,s,r,t++,this))return n}}has(a){for(let e of this){let[t]=e;if(t===a)return!0}return!1}hasValue(a){for(let[,e]of this)if(e===a)return!0;return!1}get(a){for(let e of this){let[t,n]=e;if(t===a)return n}}reduce(a,e){let t=e,n=0;for(let r of this){let[s,i]=r;t=a(t,i,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var v=class{constructor(a){V(this,"_toElementFn");if(a){let{toElementFn:e}=a;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...a){yield*this._getIterator(...a)}*values(){for(let a of this)yield a}every(a,e){let t=0;for(let n of this)if(e===void 0){if(!a(n,t++,this))return!1}else if(!a.call(e,n,t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return!0}else if(a.call(e,n,t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this)e===void 0?a(n,t++,this):a.call(e,n,t++,this)}find(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return n}else if(a.call(e,n,t++,this))return n}has(a){for(let e of this)if(e===a)return!0;return!1}reduce(a,e){let t=0,n=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let s=n.next();if(s.done)throw new TypeError("Reduce of empty structure with no initial value");r=s.value,t=1}for(let s of n)r=a(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var C=class d extends v{constructor(e=[],t){super(t);V(this,"_equals",Object.is);V(this,"_elements",[]);V(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, define a custom comparator in options.");return e>t?1:e<t?-1:0});V(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:n}=t;n&&(this._comparator=n)}this.addMany(e)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var e;return(e=this.elements[this.size-1])!=null?e:void 0}static from(e,t){return new this(e,t)}static heapify(e,t){return new d(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}addMany(e){let t=[];for(let n of e)if(this.toElementFn){let r=this.add(this.toElementFn(n));t.push(r)}else{let r=this.add(n);t.push(r)}return t}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=Array.from(e),this.fix()}has(e){for(let t of this.elements)if(this._equals(t,e))return!0;return!1}delete(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(this._equals(this.elements[n],e)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}deleteBy(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(e(this.elements[n],n,this)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}setEquality(e){return this._equals=e,this}dfs(e="PRE"){let t=[],n=r=>{let s=2*r+1,i=s+1;r<this.size&&(e==="IN"?(n(s),t.push(this.elements[r]),n(i)):e==="PRE"?(t.push(this.elements[r]),n(s),n(i)):e==="POST"&&(n(s),n(i),t.push(this.elements[r])))};return n(0),t}fix(){let e=[];for(let t=Math.floor(this.size/2)-1;t>=0;t--)e.push(this._sinkDown(t,this.elements.length>>1));return e}sort(){let e=[],t=this._createInstance();for(let n of this.elements)t.add(n);for(;!t.isEmpty();){let n=t.poll();n!==void 0&&e.push(n)}return e}clone(){let e=this._createInstance();for(let t of this.elements)e.add(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)(t===void 0?e(s,r++,this):e.call(t,s,r++,this))?n.add(s):r++;return n}map(e,t,n){let{comparator:r,toElementFn:s,...i}=t!=null?t:{};if(!r)throw new TypeError("Heap.map requires options.comparator for EM");let o=this._createLike([],{...i,comparator:r,toElementFn:s}),l=0;for(let f of this){let u=n===void 0?e(f,l++,this):e.call(n,f,l++,this);o.add(u)}return o}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let i=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(i)}return n}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let n=e-1>>1,r=this.elements[n];if(this.comparator(r,t)<=0)break;this.elements[e]=r,e=n}return this.elements[e]=t,!0}_sinkDown(e,t){let n=this.elements[e];for(;e<t;){let r=e<<1|1,s=r+1,i=this.elements[r];if(s<this.elements.length&&this.comparator(i,this.elements[s])>0&&(r=s,i=this.elements[s]),this.comparator(i,n)>=0)break;this.elements[e]=i,e=r}return this.elements[e]=n,!0}_createInstance(e){let t=this.constructor;return new t([],{comparator:this.comparator,toElementFn:this.toElementFn,...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}};var A=class d extends v{constructor(e){super(e);V(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let r=this.at(n);if(r!==void 0&&e.call(t,r,n,this))return n}return-1}concat(...e){let t=this.clone();for(let n of e)n instanceof d?t.pushMany(n):t.push(n);return t}sort(e){let t=this.toArray();t.sort(e),this.clear();for(let n of t)this.push(n);return this}splice(e,t=0,...n){let r=this._createInstance();e=e<0?this.length+e:e,e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));for(let s=0;s<t;s++){let i=this.deleteAt(e);i!==void 0&&r.push(i)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);return r}join(e=","){return this.toArray().join(e)}toReversedArray(){let e=[];for(let t=this.length-1;t>=0;t--)e.push(this.at(t));return e}reduceRight(e,t){let n=t!=null?t:0;for(let r=this.length-1;r>=0;r--)n=e(n,this.at(r),r,this);return n}slice(e=0,t=this.length){e=e<0?this.length+e:e,t=t<0?this.length+t:t;let n=this._createInstance();for(let r=e;r<t;r++)n.push(this.at(r));return n}fill(e,t=0,n=this.length){if(t=t<0?this.length+t:t,n=n<0?this.length+n:n,t<0&&(t=0),n>this.length&&(n=this.length),t>=n)return this;for(let r=t;r<n;r++)this.setAt(r,e);return this}};var L=class d extends A{constructor(e=[],t){super(t);V(this,"_elements",[]);V(this,"_offset",0);V(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new d(e)}isEmpty(){return this.length===0}push(e){return this.elements.push(e),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}shift(){if(this.length===0)return;let e=this.first;return this._offset+=1,this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){for(let t=this._offset;t<this.elements.length;t++)if(Object.is(this.elements[t],e))return this.elements.splice(t,1),!0;return!1}at(e){if(!(e<0||e>=this.length))return this._elements[this._offset+e]}deleteAt(e){if(e<0||e>=this.length)return;let t=this._offset+e,[n]=this.elements.splice(t,1);return n}addAt(e,t){return e<0||e>this.length?!1:(this._elements.splice(this._offset+e,0,t),!0)}setAt(e,t){return e<0||e>=this.length?!1:(this._elements[this._offset+e]=t,!0)}reverse(){return this._elements=this.elements.slice(this._offset).reverse(),this._offset=0,this}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this._offset),this._offset=0,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));let r=this._offset+e,s=this._elements.splice(r,t,...n);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return i._setAutoCompactRatio(this._autoCompactRatio),i.pushMany(s),i}clone(){let e=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});e._setAutoCompactRatio(this._autoCompactRatio);for(let t=this._offset;t<this.elements.length;t++)e.push(this.elements[t]);return e}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setAutoCompactRatio(this._autoCompactRatio);let r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}map(e,t,n){var i,o;let r=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(i=t==null?void 0:t.maxLen)!=null?i:this._maxLen,autoCompactRatio:(o=t==null?void 0:t.autoCompactRatio)!=null?o:this._autoCompactRatio}),s=0;for(let l of this)r.push(n===void 0?e(l,s++,this):e.call(n,l,s++,this));return r}mapSame(e,t){var i;let n=this.constructor,r=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(i=r._setAutoCompactRatio)==null||i.call(r,this._autoCompactRatio);let s=0;for(let o of this){let l=t===void 0?e(o,s++,this):e.call(t,o,s++,this);r.push(l)}return r}_setAutoCompactRatio(e){this._autoCompactRatio=e}*_getIterator(){for(let e=this._offset;e<this.elements.length;e++)yield this.elements[e]}*_getReverseIterator(){for(let e=this.length-1;e>=0;e--){let t=this.at(e);t!==void 0&&(yield t)}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}};var R=class{constructor(a,e){V(this,"key");V(this,"value");this.key=a,this.value=e}},K=class{constructor(a,e){V(this,"value");V(this,"weight");V(this,"_hashCode");this.weight=a!==void 0?a:1,this.value=e,this._hashCode=j()}get hashCode(){return this._hashCode}},T=class extends N{constructor(e){super();V(this,"_options",{defaultEdgeWeight:1});V(this,"_vertexMap",new Map);let t=e==null?void 0:e.graph;this._options={defaultEdgeWeight:1,...t!=null?t:{}}}get options(){return this._options}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof R)return this._addVertex(e);{let n=this.createVertex(e,t);return this._addVertex(n)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let n of e)t.push(this.deleteVertex(n));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,n,r){if(e instanceof K)return this._addEdge(e);if(t instanceof R||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof R&&(e=e.key),t instanceof R&&(t=t.key);let s=this.createEdge(e,t,n,r);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,n){let r=this.getEdge(e,t);return r?(r.weight=n,!0):!1}getAllPathsBetween(e,t,n=1e3){let r=[],s=this._getVertex(e),i=this._getVertex(t);if(!(s&&i))return[];let o=[];for(o.push({vertex:s,path:[s]});o.length>0;){let{vertex:l,path:f}=o.pop();if(l===i&&(r.push(f),r.length>=n))return r;let u=this.getNeighbors(l);for(let c of u)if(!f.includes(c)){let E=[...f,c];o.push({vertex:c,path:E})}}return r}getPathSumWeight(e){var n;let t=0;for(let r=0;r<e.length;r++)t+=((n=this.getEdge(e[r],e[r+1]))==null?void 0:n.weight)||0;return t}getMinCostBetween(e,t,n){if(n===void 0&&(n=!1),n){let r=this.getAllPathsBetween(e,t),s=Number.MAX_SAFE_INTEGER;for(let i of r)s=Math.min(this.getPathSumWeight(i),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let i=new Map,o=new L([s]);i.set(s,!0);let l=0;for(;o.length>0;){for(let f=0,u=o.length;f<u;f++){let c=o.shift();if(c===r)return l;if(c!==void 0){let E=this.getNeighbors(c);for(let x of E)i.has(x)||(i.set(x,!0),o.push(x))}}l++}return}}getMinPathBetween(e,t,n,r=!1){var s,i;if(n===void 0&&(n=!1),n)if(r){let o=this.getAllPathsBetween(e,t,1e4),l=Number.MAX_SAFE_INTEGER,f=-1,u=0;for(let c of o){let E=this.getPathSumWeight(c);E<l&&(l=E,f=u),u++}return o[f]||void 0}else return(i=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?i:[];else{let o=[],l=this._getVertex(e),f=this._getVertex(t);if(!(l&&f))return[];let u=(c,E,x,y)=>{if(x.add(c),c===E){o=[l,...y];return}let M=this.getNeighbors(c);for(let k of M)x.has(k)||(y.push(k),u(k,E,x,y),y.pop());x.delete(c)};return u(l,f,new Set,[]),o}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,i,o=[],l=[],f=this._vertexMap,u=new Map,c=new Set,E=new Map,x=this._getVertex(e),y=t?this._getVertex(t):void 0;if(!x)return;for(let b of f){let h=b[1];h instanceof R&&u.set(h,Number.MAX_SAFE_INTEGER)}u.set(x,0),E.set(x,void 0);let M=()=>{let b=Number.MAX_SAFE_INTEGER,h;for(let[p,m]of u)c.has(p)||m<b&&(b=m,h=p);return h},k=b=>{for(let h of f){let p=h[1];if(p instanceof R){let m=[p],g=E.get(p);for(;g;)m.push(g),g=E.get(g);let _=m.reverse();h[1]===b&&(o=_),l.push(_)}}};for(let b=1;b<f.size;b++){let h=M();if(h){if(c.add(h),y&&y===h)return n&&(s=u.get(y)||Number.MAX_SAFE_INTEGER),r&&k(y),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o};let p=this.getNeighbors(h);for(let m of p)if(!c.has(m)){let g=this.getEdge(h,m);if(g){let _=u.get(h),O=u.get(m);_!==void 0&&O!==void 0&&g.weight+_<O&&(u.set(m,g.weight+_),E.set(m,h))}}}}return n&&u.forEach((b,h)=>{h!==x&&b<s&&(s=b,r&&(i=h))}),r&&k(i),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o}}dijkstra(e,t=void 0,n=!1,r=!1){var b;let s=Number.MAX_SAFE_INTEGER,i,o=[],l=[],f=this._vertexMap,u=new Map,c=new Set,E=new Map,x=this._getVertex(e),y=t?this._getVertex(t):void 0;if(!x)return;for(let h of f){let p=h[1];p instanceof R&&u.set(p,Number.MAX_SAFE_INTEGER)}let M=new C([],{comparator:(h,p)=>h.key-p.key});M.add({key:0,value:x}),u.set(x,0),E.set(x,void 0);let k=h=>{for(let p of f){let m=p[1];if(m instanceof R){let g=[m],_=E.get(m);for(;_;)g.push(_),_=E.get(_);let O=g.reverse();p[1]===h&&(o=O),l.push(O)}}};for(;M.size>0;){let h=M.poll(),p=h==null?void 0:h.key,m=h==null?void 0:h.value;if(p!==void 0&&m){if(c.add(m),y&&y===m)return n&&(s=u.get(y)||Number.MAX_SAFE_INTEGER),r&&k(y),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o};let g=this.getNeighbors(m);for(let _ of g)if(!c.has(_)){let O=(b=this.getEdge(m,_))==null?void 0:b.weight;if(typeof O=="number"){let w=u.get(_);w!==void 0&&p+O<w&&(M.add({key:p+O,value:_}),E.set(_,m),u.set(_,p+O))}}}}return n&&u.forEach((h,p)=>{p!==x&&h<s&&(s=h,r&&(i=p))}),r&&k(i),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),i=[],o=new Map,l=new Map,f=Number.MAX_SAFE_INTEGER,u=[],c;if(t&&(c=!1),!s)return{hasNegativeCycle:c,distMap:o,preMap:l,paths:i,min:f,minPath:u};let E=this._vertexMap,x=E.size,y=this.edgeSet(),M=y.length;this._vertexMap.forEach(b=>{o.set(b,Number.MAX_SAFE_INTEGER)}),o.set(s,0);for(let b=1;b<x;++b)for(let h=0;h<M;++h){let p=this.getEndsOfEdge(y[h]);if(p){let[m,g]=p,_=y[h].weight,O=o.get(m),w=o.get(g);O!==void 0&&w!==void 0&&o.get(m)!==Number.MAX_SAFE_INTEGER&&O+_<w&&(o.set(g,O+_),r&&l.set(g,m))}}let k;if(n&&o.forEach((b,h)=>{h!==s&&b<f&&(f=b,r&&(k=h))}),r)for(let b of E){let h=b[1];if(h instanceof R){let p=[h],m=l.get(h);for(;m!==void 0;)p.push(m),m=l.get(m);let g=p.reverse();b[1]===k&&(u=g),i.push(g)}}for(let b=0;b<M;++b){let h=this.getEndsOfEdge(y[b]);if(h){let[p]=h,m=y[b].weight,g=o.get(p);g&&g!==Number.MAX_SAFE_INTEGER&&g+m<g&&(c=!0)}}return{hasNegativeCycle:c,distMap:o,preMap:l,paths:i,min:f,minPath:u}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],r=[];for(let i=0;i<t;i++){n[i]=[],r[i]=[];for(let o=0;o<t;o++)r[i][o]=void 0}for(let i=0;i<t;i++)for(let o=0;o<t;o++)n[i][o]=((s=this.getEdge(e[i][1],e[o][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let i=0;i<t;i++)for(let o=0;o<t;o++)for(let l=0;l<t;l++)n[o][l]>n[o][i]+n[i][l]&&(n[o][l]=n[o][i]+n[i][l],r[o][l]=e[i][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(i,o,l)=>{if(l.has(i)){(!e&&o.length>2||e&&o.length>=2)&&o[0]===i.key&&t.push([...o]);return}l.add(i),o.push(i.key);for(let f of this.getNeighbors(i))f&&r(f,o,l);l.delete(i),o.pop()};for(let i of this.vertexMap.values())r(i,[],n);let s=new Map;for(let i of t){let o=[...i].sort().toString();s.has(o)||s.set(o,i)}return[...s].map(i=>i[1])}filter(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return this._createLike(n,this._snapshotOptions())}filterEntries(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return n}map(e,t){let n=[],r=0;for(let[s,i]of this)n.push(e.call(t,i,s,r,this)),r++;return n}clone(){return this._createLike(void 0,this._snapshotOptions())}*_getIterator(){for(let e of this._vertexMap.values())yield[e.key,e.value]}_snapshotOptions(){return{graph:{...this._options}}}_createInstance(e){let t=this.constructor,n=new t,r=e==null?void 0:e.graph;return r?n._options={...n._options,...r}:n._options={...n._options,...this._options},n}_createLike(e,t){let n=this._createInstance(t);if(e)for(let[s,i]of e)n.addVertex(s,i);else for(let[s,i]of this)n.addVertex(s,i);let r=this.edgeSet();for(let s of r){let i=this.getEndsOfEdge(s);if(!i)continue;let[o,l]=i,f=o.key,u=l.key,c=n.hasVertex?n.hasVertex(f):!1,E=n.hasVertex?n.hasVertex(u):!1;if(c&&E){let x=s.weight,y=s.value,M=n.createEdge(f,u,x,y);n._addEdge(M)}}return n}_addVertex(e){return this.hasVertex(e)?!1:(this._vertexMap.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertexMap.get(t)||void 0}_getVertexKey(e){return e instanceof R?e.key:e}};var F=class extends R{constructor(a,e){super(a,e)}},S=class extends K{constructor(e,t,n,r){super(n,r);V(this,"endpoints");this.endpoints=[e,t]}},H=class d extends T{constructor(e){super(e);V(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}static fromKeys(e){let t=new d({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new d;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new F(e,t)}createEdge(e,t,n,r){var s;return new S(e,t,(s=n!=null?n:this.options.defaultEdgeWeight)!=null?s:1,r)}getEdge(e,t){var r;let n=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),i=this._getVertex(t);s&&i&&(n=(r=this._edgeMap.get(s))==null?void 0:r.filter(o=>o.endpoints.includes(i.key)))}return n&&n[0]||void 0}deleteEdgeBetween(e,t){let n=this._getVertex(e),r=this._getVertex(t);if(!n||!r)return;let s=this._edgeMap.get(n),i;s&&(i=U(s,l=>l.endpoints.includes(r.key))[0]||void 0);let o=this._edgeMap.get(r);return o&&U(o,l=>l.endpoints.includes(n.key)),i}deleteEdge(e,t){let n,r;if(this.isVertexKey(e))if(this.isVertexKey(t))n=this._getVertex(e),r=this._getVertex(t);else return;else n=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(n&&r)return this.deleteEdgeBetween(n,r)}deleteVertex(e){let t,n;this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e));let r=this.getNeighbors(e);return n&&(r.forEach(s=>{let i=this._edgeMap.get(s);if(i){let o=i.filter(l=>!l.endpoints.includes(t));this._edgeMap.set(s,o)}}),this._edgeMap.delete(n)),this._vertexMap.delete(t)}degreeOf(e){var n;let t=this._getVertex(e);return t&&((n=this._edgeMap.get(t))==null?void 0:n.length)||0}edgesOf(e){let t=this._getVertex(e);return t?this._edgeMap.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edgeMap.forEach(t=>{t.forEach(n=>{e.add(n)})}),[...e]}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let r=this.edgesOf(n);for(let s of r){let i=this._getVertex(s.endpoints.filter(o=>o!==n.key)[0]);i&&t.push(i)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.endpoints[0],e.endpoints[1]))return;let t=this._getVertex(e.endpoints[0]),n=this._getVertex(e.endpoints[1]);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){return super.clone()}tarjan(){let e=new Map,t=new Map,n=[],r=[],s=0,i=(o,l)=>{e.set(o,s),t.set(o,s),s++;let f=this.getNeighbors(o),u=0;for(let c of f)if(e.has(c))c!==l&&t.set(o,Math.min(t.get(o),e.get(c)));else{if(u++,i(c,o),t.set(o,Math.min(t.get(o),t.get(c))),t.get(c)>e.get(o)){let E=this.getEdge(o,c);E&&n.push(E)}l!==void 0&&t.get(c)>=e.get(o)&&r.push(o)}l===void 0&&u>1&&r.push(o)};for(let o of this.vertexMap.values())e.has(o)||i(o,void 0);return{dfnMap:e,lowMap:t,bridges:n,cutVertices:r}}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(e){for(let t of e.endpoints){let n=this._getVertex(t);if(n===void 0)return!1;if(n){let r=this._edgeMap.get(n);r?r.push(e):this._edgeMap.set(n,[e])}}return!0}};var z=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(z||{}),D=class{constructor(a,e,t=!0,n=!0){this.low=a;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(a,e){let t=this.includeLow?e(a,this.low)>=0:e(a,this.low)>0,n=this.includeHigh?e(a,this.high)<=0:e(a,this.high)<0;return t&&n}};return q(J);})();
1
+ "use strict";var undirectedGraphTyped=(()=>{var I=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var W=(f,a,e)=>a in f?I(f,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[a]=e;var Q=(f,a)=>{for(var e in a)I(f,e,{get:a[e],enumerable:!0})},X=(f,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of P(a))!B.call(f,n)&&n!==e&&I(f,n,{get:()=>a[n],enumerable:!(t=G(a,n))||t.enumerable});return f};var q=f=>X(I({},"__esModule",{value:!0}),f);var V=(f,a,e)=>W(f,typeof a!="symbol"?a+"":a,e);var J={};Q(J,{DFSOperation:()=>z,Range:()=>D,UndirectedEdge:()=>S,UndirectedGraph:()=>H,UndirectedVertex:()=>F});var j=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(f){let a=Math.random()*16|0;return(f=="x"?a:a&3|8).toString(16)})},U=function(f,a){let e=-1,t=f?f.length:0,n=[];for(;++e<t;){let r=f[e];a(r,e,f)&&(n.push(r),Array.prototype.splice.call(f,e--,1),t--)}return n};var N=class{*[Symbol.iterator](...a){yield*this._getIterator(...a)}*entries(){for(let a of this)yield a}*keys(){for(let a of this)yield a[0]}*values(){for(let a of this)yield a[1]}every(a,e){let t=0;for(let n of this)if(!a.call(e,n[1],n[0],t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(a.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this){let[r,s]=n;a.call(e,s,r,t++,this)}}find(a,e){let t=0;for(let n of this){let[r,s]=n;if(a.call(e,s,r,t++,this))return n}}has(a){for(let e of this){let[t]=e;if(t===a)return!0}return!1}hasValue(a){for(let[,e]of this)if(e===a)return!0;return!1}get(a){for(let e of this){let[t,n]=e;if(t===a)return n}}reduce(a,e){let t=e,n=0;for(let r of this){let[s,i]=r;t=a(t,i,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var v=class{constructor(a){V(this,"_toElementFn");if(a){let{toElementFn:e}=a;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...a){yield*this._getIterator(...a)}*values(){for(let a of this)yield a}every(a,e){let t=0;for(let n of this)if(e===void 0){if(!a(n,t++,this))return!1}else if(!a.call(e,n,t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return!0}else if(a.call(e,n,t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this)e===void 0?a(n,t++,this):a.call(e,n,t++,this)}find(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return n}else if(a.call(e,n,t++,this))return n}has(a){for(let e of this)if(e===a)return!0;return!1}reduce(a,e){let t=0,n=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let s=n.next();if(s.done)throw new TypeError("Reduce of empty structure with no initial value");r=s.value,t=1}for(let s of n)r=a(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var C=class f extends v{constructor(e=[],t){super(t);V(this,"_equals",Object.is);V(this,"_elements",[]);V(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, define a custom comparator in options.");return e>t?1:e<t?-1:0});V(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:n}=t;n&&(this._comparator=n)}this.addMany(e)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var e;return(e=this.elements[this.size-1])!=null?e:void 0}static from(e,t){return new this(e,t)}static heapify(e,t){return new f(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}addMany(e){let t=[];for(let n of e)if(this.toElementFn){let r=this.add(this.toElementFn(n));t.push(r)}else{let r=this.add(n);t.push(r)}return t}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=Array.from(e),this.fix()}has(e){for(let t of this.elements)if(this._equals(t,e))return!0;return!1}delete(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(this._equals(this.elements[n],e)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}deleteBy(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(e(this.elements[n],n,this)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}setEquality(e){return this._equals=e,this}dfs(e="PRE"){let t=[],n=r=>{let s=2*r+1,i=s+1;r<this.size&&(e==="IN"?(n(s),t.push(this.elements[r]),n(i)):e==="PRE"?(t.push(this.elements[r]),n(s),n(i)):e==="POST"&&(n(s),n(i),t.push(this.elements[r])))};return n(0),t}fix(){let e=[];for(let t=Math.floor(this.size/2)-1;t>=0;t--)e.push(this._sinkDown(t,this.elements.length>>1));return e}sort(){let e=[],t=this._createInstance();for(let n of this.elements)t.add(n);for(;!t.isEmpty();){let n=t.poll();n!==void 0&&e.push(n)}return e}clone(){let e=this._createInstance();for(let t of this.elements)e.add(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)(t===void 0?e(s,r++,this):e.call(t,s,r++,this))?n.add(s):r++;return n}map(e,t,n){let{comparator:r,toElementFn:s,...i}=t!=null?t:{};if(!r)throw new TypeError("Heap.map requires options.comparator for EM");let o=this._createLike([],{...i,comparator:r,toElementFn:s}),l=0;for(let d of this){let u=n===void 0?e(d,l++,this):e.call(n,d,l++,this);o.add(u)}return o}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let i=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(i)}return n}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let n=e-1>>1,r=this.elements[n];if(this.comparator(r,t)<=0)break;this.elements[e]=r,e=n}return this.elements[e]=t,!0}_sinkDown(e,t){let n=this.elements[e];for(;e<t;){let r=e<<1|1,s=r+1,i=this.elements[r];if(s<this.elements.length&&this.comparator(i,this.elements[s])>0&&(r=s,i=this.elements[s]),this.comparator(i,n)>=0)break;this.elements[e]=i,e=r}return this.elements[e]=n,!0}_createInstance(e){let t=this.constructor;return new t([],{comparator:this.comparator,toElementFn:this.toElementFn,...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}};var A=class f extends v{constructor(e){super(e);V(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let r=this.at(n);if(r!==void 0&&e.call(t,r,n,this))return n}return-1}concat(...e){let t=this.clone();for(let n of e)n instanceof f?t.pushMany(n):t.push(n);return t}sort(e){let t=this.toArray();t.sort(e),this.clear();for(let n of t)this.push(n);return this}splice(e,t=0,...n){let r=this._createInstance();e=e<0?this.length+e:e,e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));for(let s=0;s<t;s++){let i=this.deleteAt(e);i!==void 0&&r.push(i)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);return r}join(e=","){return this.toArray().join(e)}toReversedArray(){let e=[];for(let t=this.length-1;t>=0;t--)e.push(this.at(t));return e}reduceRight(e,t){let n=t!=null?t:0;for(let r=this.length-1;r>=0;r--)n=e(n,this.at(r),r,this);return n}slice(e=0,t=this.length){e=e<0?this.length+e:e,t=t<0?this.length+t:t;let n=this._createInstance();for(let r=e;r<t;r++)n.push(this.at(r));return n}fill(e,t=0,n=this.length){if(t=t<0?this.length+t:t,n=n<0?this.length+n:n,t<0&&(t=0),n>this.length&&(n=this.length),t>=n)return this;for(let r=t;r<n;r++)this.setAt(r,e);return this}};var T=class f extends A{constructor(e=[],t){super(t);V(this,"_elements",[]);V(this,"_offset",0);V(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new f(e)}isEmpty(){return this.length===0}push(e){return this.elements.push(e),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}shift(){if(this.length===0)return;let e=this.first;return this._offset+=1,this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){for(let t=this._offset;t<this.elements.length;t++)if(Object.is(this.elements[t],e))return this.elements.splice(t,1),!0;return!1}at(e){if(!(e<0||e>=this.length))return this._elements[this._offset+e]}deleteAt(e){if(e<0||e>=this.length)return;let t=this._offset+e,[n]=this.elements.splice(t,1);return n}addAt(e,t){return e<0||e>this.length?!1:(this._elements.splice(this._offset+e,0,t),!0)}setAt(e,t){return e<0||e>=this.length?!1:(this._elements[this._offset+e]=t,!0)}reverse(){return this._elements=this.elements.slice(this._offset).reverse(),this._offset=0,this}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this._offset),this._offset=0,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));let r=this._offset+e,s=this._elements.splice(r,t,...n);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return i._setAutoCompactRatio(this._autoCompactRatio),i.pushMany(s),i}clone(){let e=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});e._setAutoCompactRatio(this._autoCompactRatio);for(let t=this._offset;t<this.elements.length;t++)e.push(this.elements[t]);return e}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setAutoCompactRatio(this._autoCompactRatio);let r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}map(e,t,n){var i,o;let r=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(i=t==null?void 0:t.maxLen)!=null?i:this._maxLen,autoCompactRatio:(o=t==null?void 0:t.autoCompactRatio)!=null?o:this._autoCompactRatio}),s=0;for(let l of this)r.push(n===void 0?e(l,s++,this):e.call(n,l,s++,this));return r}mapSame(e,t){var i;let n=this.constructor,r=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(i=r._setAutoCompactRatio)==null||i.call(r,this._autoCompactRatio);let s=0;for(let o of this){let l=t===void 0?e(o,s++,this):e.call(t,o,s++,this);r.push(l)}return r}_setAutoCompactRatio(e){this._autoCompactRatio=e}*_getIterator(){for(let e=this._offset;e<this.elements.length;e++)yield this.elements[e]}*_getReverseIterator(){for(let e=this.length-1;e>=0;e--){let t=this.at(e);t!==void 0&&(yield t)}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}};var R=class{constructor(a,e){V(this,"key");V(this,"value");this.key=a,this.value=e}},K=class{constructor(a,e){V(this,"value");V(this,"weight");V(this,"_hashCode");this.weight=a!==void 0?a:1,this.value=e,this._hashCode=j()}get hashCode(){return this._hashCode}},L=class extends N{constructor(e){super();V(this,"_options",{defaultEdgeWeight:1});V(this,"_vertexMap",new Map);let t=e==null?void 0:e.graph;this._options={defaultEdgeWeight:1,...t!=null?t:{}}}get options(){return this._options}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof R)return this._addVertex(e);{let n=this.createVertex(e,t);return this._addVertex(n)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let n of e)t.push(this.deleteVertex(n));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,n,r){if(e instanceof K)return this._addEdge(e);if(t instanceof R||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof R&&(e=e.key),t instanceof R&&(t=t.key);let s=this.createEdge(e,t,n,r);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,n){let r=this.getEdge(e,t);return r?(r.weight=n,!0):!1}getAllPathsBetween(e,t,n=1e3){let r=[],s=this._getVertex(e),i=this._getVertex(t);if(!(s&&i))return[];let o=[];for(o.push({vertex:s,path:[s]});o.length>0;){let{vertex:l,path:d}=o.pop();if(l===i&&(r.push(d),r.length>=n))return r;let u=this.getNeighbors(l);for(let c of u)if(!d.includes(c)){let E=[...d,c];o.push({vertex:c,path:E})}}return r}getPathSumWeight(e){var n;let t=0;for(let r=0;r<e.length;r++)t+=((n=this.getEdge(e[r],e[r+1]))==null?void 0:n.weight)||0;return t}getMinCostBetween(e,t,n){if(n===void 0&&(n=!1),n){let r=this.getAllPathsBetween(e,t),s=Number.MAX_SAFE_INTEGER;for(let i of r)s=Math.min(this.getPathSumWeight(i),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let i=new Map,o=new T([s]);i.set(s,!0);let l=0;for(;o.length>0;){for(let d=0,u=o.length;d<u;d++){let c=o.shift();if(c===r)return l;if(c!==void 0){let E=this.getNeighbors(c);for(let x of E)i.has(x)||(i.set(x,!0),o.push(x))}}l++}return}}getMinPathBetween(e,t,n,r=!1){var s,i;if(n===void 0&&(n=!1),n)if(r){let o=this.getAllPathsBetween(e,t,1e4),l=Number.MAX_SAFE_INTEGER,d=-1,u=0;for(let c of o){let E=this.getPathSumWeight(c);E<l&&(l=E,d=u),u++}return o[d]||void 0}else return(i=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?i:[];else{let o=[],l=this._getVertex(e),d=this._getVertex(t);if(!(l&&d))return[];let u=(c,E,x,y)=>{if(x.add(c),c===E){o=[l,...y];return}let M=this.getNeighbors(c);for(let k of M)x.has(k)||(y.push(k),u(k,E,x,y),y.pop());x.delete(c)};return u(l,d,new Set,[]),o}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,i,o=[],l=[],d=this._vertexMap,u=new Map,c=new Set,E=new Map,x=this._getVertex(e),y=t?this._getVertex(t):void 0;if(!x)return;for(let b of d){let h=b[1];h instanceof R&&u.set(h,Number.MAX_SAFE_INTEGER)}u.set(x,0),E.set(x,void 0);let M=()=>{let b=Number.MAX_SAFE_INTEGER,h;for(let[p,m]of u)c.has(p)||m<b&&(b=m,h=p);return h},k=b=>{for(let h of d){let p=h[1];if(p instanceof R){let m=[p],g=E.get(p);for(;g;)m.push(g),g=E.get(g);let _=m.reverse();h[1]===b&&(o=_),l.push(_)}}};for(let b=1;b<d.size;b++){let h=M();if(h){if(c.add(h),y&&y===h)return n&&(s=u.get(y)||Number.MAX_SAFE_INTEGER),r&&k(y),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o};let p=this.getNeighbors(h);for(let m of p)if(!c.has(m)){let g=this.getEdge(h,m);if(g){let _=u.get(h),O=u.get(m);_!==void 0&&O!==void 0&&g.weight+_<O&&(u.set(m,g.weight+_),E.set(m,h))}}}}return n&&u.forEach((b,h)=>{h!==x&&b<s&&(s=b,r&&(i=h))}),r&&k(i),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o}}dijkstra(e,t=void 0,n=!1,r=!1){var b;let s=Number.MAX_SAFE_INTEGER,i,o=[],l=[],d=this._vertexMap,u=new Map,c=new Set,E=new Map,x=this._getVertex(e),y=t?this._getVertex(t):void 0;if(!x)return;for(let h of d){let p=h[1];p instanceof R&&u.set(p,Number.MAX_SAFE_INTEGER)}let M=new C([],{comparator:(h,p)=>h.key-p.key});M.add({key:0,value:x}),u.set(x,0),E.set(x,void 0);let k=h=>{for(let p of d){let m=p[1];if(m instanceof R){let g=[m],_=E.get(m);for(;_;)g.push(_),_=E.get(_);let O=g.reverse();p[1]===h&&(o=O),l.push(O)}}};for(;M.size>0;){let h=M.poll(),p=h==null?void 0:h.key,m=h==null?void 0:h.value;if(p!==void 0&&m){if(c.add(m),y&&y===m)return n&&(s=u.get(y)||Number.MAX_SAFE_INTEGER),r&&k(y),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o};let g=this.getNeighbors(m);for(let _ of g)if(!c.has(_)){let O=(b=this.getEdge(m,_))==null?void 0:b.weight;if(typeof O=="number"){let w=u.get(_);w!==void 0&&p+O<w&&(M.add({key:p+O,value:_}),E.set(_,m),u.set(_,p+O))}}}}return n&&u.forEach((h,p)=>{p!==x&&h<s&&(s=h,r&&(i=p))}),r&&k(i),{distMap:u,preMap:E,seen:c,paths:l,minDist:s,minPath:o}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),i=[],o=new Map,l=new Map,d=Number.MAX_SAFE_INTEGER,u=[],c;if(t&&(c=!1),!s)return{hasNegativeCycle:c,distMap:o,preMap:l,paths:i,min:d,minPath:u};let E=this._vertexMap,x=E.size,y=this.edgeSet(),M=y.length;this._vertexMap.forEach(b=>{o.set(b,Number.MAX_SAFE_INTEGER)}),o.set(s,0);for(let b=1;b<x;++b)for(let h=0;h<M;++h){let p=this.getEndsOfEdge(y[h]);if(p){let[m,g]=p,_=y[h].weight,O=o.get(m),w=o.get(g);O!==void 0&&w!==void 0&&o.get(m)!==Number.MAX_SAFE_INTEGER&&O+_<w&&(o.set(g,O+_),r&&l.set(g,m))}}let k;if(n&&o.forEach((b,h)=>{h!==s&&b<d&&(d=b,r&&(k=h))}),r)for(let b of E){let h=b[1];if(h instanceof R){let p=[h],m=l.get(h);for(;m!==void 0;)p.push(m),m=l.get(m);let g=p.reverse();b[1]===k&&(u=g),i.push(g)}}for(let b=0;b<M;++b){let h=this.getEndsOfEdge(y[b]);if(h){let[p]=h,m=y[b].weight,g=o.get(p);g&&g!==Number.MAX_SAFE_INTEGER&&g+m<g&&(c=!0)}}return{hasNegativeCycle:c,distMap:o,preMap:l,paths:i,min:d,minPath:u}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],r=[];for(let i=0;i<t;i++){n[i]=[],r[i]=[];for(let o=0;o<t;o++)r[i][o]=void 0}for(let i=0;i<t;i++)for(let o=0;o<t;o++)n[i][o]=((s=this.getEdge(e[i][1],e[o][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let i=0;i<t;i++)for(let o=0;o<t;o++)for(let l=0;l<t;l++)n[o][l]>n[o][i]+n[i][l]&&(n[o][l]=n[o][i]+n[i][l],r[o][l]=e[i][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(i,o,l)=>{if(l.has(i)){(!e&&o.length>2||e&&o.length>=2)&&o[0]===i.key&&t.push([...o]);return}l.add(i),o.push(i.key);for(let d of this.getNeighbors(i))d&&r(d,o,l);l.delete(i),o.pop()};for(let i of this.vertexMap.values())r(i,[],n);let s=new Map;for(let i of t){let o=[...i].sort().toString();s.has(o)||s.set(o,i)}return[...s].map(i=>i[1])}filter(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return this._createLike(n,this._snapshotOptions())}filterEntries(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return n}map(e,t){let n=[],r=0;for(let[s,i]of this)n.push(e.call(t,i,s,r,this)),r++;return n}clone(){return this._createLike(void 0,this._snapshotOptions())}*_getIterator(){for(let e of this._vertexMap.values())yield[e.key,e.value]}_snapshotOptions(){return{graph:{...this._options}}}_createInstance(e){let t=this.constructor,n=new t,r=e==null?void 0:e.graph;return r?n._options={...n._options,...r}:n._options={...n._options,...this._options},n}_createLike(e,t){let n=this._createInstance(t);if(e)for(let[s,i]of e)n.addVertex(s,i);else for(let[s,i]of this)n.addVertex(s,i);let r=this.edgeSet();for(let s of r){let i=this.getEndsOfEdge(s);if(!i)continue;let[o,l]=i,d=o.key,u=l.key,c=n.hasVertex?n.hasVertex(d):!1,E=n.hasVertex?n.hasVertex(u):!1;if(c&&E){let x=s.weight,y=s.value,M=n.createEdge(d,u,x,y);n._addEdge(M)}}return n}_addVertex(e){return this.hasVertex(e)?!1:(this._vertexMap.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertexMap.get(t)||void 0}_getVertexKey(e){return e instanceof R?e.key:e}};var F=class extends R{constructor(a,e){super(a,e)}},S=class extends K{constructor(e,t,n,r){super(n,r);V(this,"endpoints");this.endpoints=[e,t]}},H=class f extends L{constructor(e){super(e);V(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}static fromKeys(e){let t=new f({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new f;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new F(e,t)}createEdge(e,t,n,r){var s;return new S(e,t,(s=n!=null?n:this.options.defaultEdgeWeight)!=null?s:1,r)}getEdge(e,t){var r;let n=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),i=this._getVertex(t);s&&i&&(n=(r=this._edgeMap.get(s))==null?void 0:r.filter(o=>o.endpoints.includes(i.key)))}return n&&n[0]||void 0}deleteEdgeBetween(e,t){let n=this._getVertex(e),r=this._getVertex(t);if(!n||!r)return;let s=this._edgeMap.get(n),i;s&&(i=U(s,l=>l.endpoints.includes(r.key))[0]||void 0);let o=this._edgeMap.get(r);return o&&U(o,l=>l.endpoints.includes(n.key)),i}deleteEdge(e,t){let n,r;if(this.isVertexKey(e))if(this.isVertexKey(t))n=this._getVertex(e),r=this._getVertex(t);else return;else n=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(n&&r)return this.deleteEdgeBetween(n,r)}deleteVertex(e){let t,n;this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e));let r=this.getNeighbors(e);return n&&(r.forEach(s=>{let i=this._edgeMap.get(s);if(i){let o=i.filter(l=>!l.endpoints.includes(t));this._edgeMap.set(s,o)}}),this._edgeMap.delete(n)),this._vertexMap.delete(t)}degreeOf(e){var n;let t=this._getVertex(e);return t&&((n=this._edgeMap.get(t))==null?void 0:n.length)||0}edgesOf(e){let t=this._getVertex(e);return t?this._edgeMap.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edgeMap.forEach(t=>{t.forEach(n=>{e.add(n)})}),[...e]}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let r=this.edgesOf(n);for(let s of r){let i=this._getVertex(s.endpoints.filter(o=>o!==n.key)[0]);i&&t.push(i)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.endpoints[0],e.endpoints[1]))return;let t=this._getVertex(e.endpoints[0]),n=this._getVertex(e.endpoints[1]);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){return super.clone()}tarjan(){let e=new Map,t=new Map,n=[],r=[],s=0,i=(o,l)=>{e.set(o,s),t.set(o,s),s++;let d=this.getNeighbors(o),u=0;for(let c of d)if(e.has(c))c!==l&&t.set(o,Math.min(t.get(o),e.get(c)));else{if(u++,i(c,o),t.set(o,Math.min(t.get(o),t.get(c))),t.get(c)>e.get(o)){let E=this.getEdge(o,c);E&&n.push(E)}l!==void 0&&t.get(c)>=e.get(o)&&r.push(o)}l===void 0&&u>1&&r.push(o)};for(let o of this.vertexMap.values())e.has(o)||i(o,void 0);return{dfnMap:e,lowMap:t,bridges:n,cutVertices:r}}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(e){for(let t of e.endpoints){let n=this._getVertex(t);if(n===void 0)return!1;if(n){let r=this._edgeMap.get(n);r?r.push(e):this._edgeMap.set(n,[e])}}return!0}};var z=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(z||{}),D=class{constructor(a,e,t=!0,n=!0){this.low=a;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(a,e){let t=this.includeLow?e(a,this.low)>=0:e(a,this.low)>0,n=this.includeHigh?e(a,this.high)<=0:e(a,this.high)<0;return t&&n}};return q(J);})();
2
2
  /**
3
3
  * data-structure-typed
4
4
  *