邊緣人一號
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # [MIT QUIZ] Graph 好像很多dp問題都可以用graph解決 Edit distance Square depth 發現很多graph題目都是改input Type 0-1 BFS 1-2 BFS Create 2 vertex Alternate driving car (How I meet your midterm ) Changing Color Road block Star Power Many-sink/source max-flow problem 有一種問題是把一個問題model成一個graph problem word ladder 沒想到這種sequence similarity的題目可以用graph來model Square Depth A Vacation Home in Hawaii :::success # Number Of Paths From Source to Destination ::: ## DAGs Path - Number of path from s->t is odd/even ![](https://i.imgur.com/Kw8ax1S.png) ![](https://i.imgur.com/ZDsCAE9.png) ## ==Average Length in DAGs== ![](https://i.imgur.com/ZE8EfxR.jpg) ## Number of shortest path from s to t with unit distance in undirected graph >跟 __Average Length in DAGs__ 可以比較 > 上題是求有多少條path > 此題是求有多少條shortest path ![](https://i.imgur.com/y6w70rC.png) ![](https://i.imgur.com/k9gDH87.png) :::success # Advanced BFS ::: ## 0-1 BFS ### Solution 1 - Supernode ![](https://i.imgur.com/tWLPYgn.png) ### [Solution 2](https://codeforces.com/blog/entry/22276) - dequeue ### 0-1 BFS example ![](https://i.imgur.com/GPBwDkT.png) ## 1-2 BFS ![](https://i.imgur.com/iJU6kdM.png) ###### tags: 'dequeue' :::info ### 其實如果weight不大都可以採用使手法 -$O(WV\log WV+WE)$ ::: >Ref:https://codeforces.com/blog/entry/22276 ## SuperNode ![](https://i.imgur.com/MGdBgUX.png) :::success # Change Transformation - Create A Copy Of Each Vertex ::: :::info Use Dijkstra as BLOCK-BOX ::: ## How I meet Your Midterm - Alternate Pass ![](https://i.imgur.com/qtR2eft.png) ## Shortest Path With ==Odd== Length :::info 比較:__"[DAGs Path - Number of path from s->t is odd/even](https://hackmd.io/h1SAF0J5S-C5CvKc5IIYAA?view#DAGs-Path---Number-of-path-from-s-gtt-is-oddeven)"__ ::: ![](https://i.imgur.com/9tTjWoz.png) ## Changing Color - Different Color Edge, More 5 Cost ![](https://i.imgur.com/93Q45Xp.png) ## Star Power! - Only 1 Free Weight At You Please ![](https://i.imgur.com/N9wplTa.jpg) ## Road Network - Only 1 Cross Block At You Please ![](https://i.imgur.com/g0sAIKG.png) ## shortest path ==exactly== k vertex - ==$O(kE+kV \log kV)$== :::danger 一個是at most => bellhman ford 一個是exactly => create copy of vertex compare with [this](https://hackmd.io/NyokPtbmSUebzIZLSN5ZNQ?view#Smallest-cost-from-s-to-t-with-exactly-edge) ::: :::info 比較 __"[[Bellman Ford]Shortest path with ~~exactly~~ ==at most== 𝑘 edges](https://hackmd.io/h1SAF0J5S-C5CvKc5IIYAA?view#Bellman-FordShortest-path-with-exactly-at-most-k-edges)"__ ::: ![](https://i.imgur.com/gXoEbEB.png) ### Not exactly >最後要抓的東西必較多,ending node要全抓 ![](https://i.imgur.com/N9YdNU2.png) ## Traffic Planning ![](https://i.imgur.com/GDtNY18.png) ![](https://i.imgur.com/GdmXDEs.png) :::info ## 這種給定每個edge距離,又希望越早到的問題,通常的解法是 ==複製每一個node的個數。== ::: ## 重點 ### 重點一:每一個vertex複製到 $T+1$ 份 ex: 1. 假設最多 $T$ 天要到目的地 => 每個node複製到有 $T+1$ 個 3. 希望有接下來 $k$ 小時會到 => 每個ndoe複製到有 $k+1$ 個 4. 希望剛好第 $m$ 天到 => 每個node複製到有 $m+1$ 個 >Take case 1 for example: > ==$u$ => $u_{d}$ $\ \ d=0,1,2...T$== ### 重點二:同一個node間得edge? 1. 如果沒特別說 => 就由上到下把 __依序__ 同一個node裡面的node用 $weight=0$ 的edge連起來。 2. 如果說同一個地方不能待超過2天 => 同一個node裡面的node都不連起來 ### 重點三:不同個node間的edge? 1. 給定一個函數$f(u,v,t)$説從 $u$ 到 $v$ 所需要花 $t$ 單位的時間 以及$g(u,v)$作為之間的距離 => ==add edge $(u_t,v_{t+f(u,v,t)})$ with weight = $g(u,v)$== ### 重點四:目標 >假設 $s$ 是起點, $t$ 是終點。 從$s_{0}$作為source做 Dijkstra 1. 越早到越好 => 從$t_{0},t_{1}...t_{T}$前面開始找第一個不為inifinity的為答案。 2. 只能在某個時間點剛好到 => $t_{T}$ ## Traffic Planning - Optimization in two dimensions(Time, Distance) ![](https://i.imgur.com/bWdp0N1.png) ## Traffic Planning - Optimization in one dimensions(Distance), but with Loose ++Time Constraint++ ![](https://i.imgur.com/YegbqNf.png) ![](https://i.imgur.com/YiekBOQ.png) ### Solution ![](https://i.imgur.com/6jtGymT.png) 可以看最後一個node的t=12是因為,不用像一樣找到最短時間 ## Traffic Planning - exactly $m$ days with distance constriant ![](https://i.imgur.com/mn8u5d5.png) ![](https://i.imgur.com/1wnnK6a.png) :::success # Graph Model ::: ## Word Ladder - Graph Modeling ![](https://i.imgur.com/nsjZIJW.png) ## [SpeedUp]Word Ladder ![](https://i.imgur.com/QhwtvVh.png) ![](https://i.imgur.com/o2nwOZ5.png) ref: https://www.programcreek.com/2012/12/leetcode-word-ladder/ ### Use BFS and Save The Cost Of Construction Of Graph - $O(n^2m)$ ##### Complexity ![](https://i.imgur.com/x4HccW7.png) #### Key Point : Checking Valid Word = Check Adjacent Or Not ref:https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/ ## Square Depth - Graph Modeling ![](https://i.imgur.com/uOWHddq.png) ###### tags: `Dynamic Programming` ## A Vacation Home in Hawaii - Longest Path Modeling ![](https://i.imgur.com/BVXgVxo.png) ### Similar peoblem ![](https://i.imgur.com/BXfpYax.png) #### Solution in DP ![](https://i.imgur.com/khNXWFT.png) ![](https://i.imgur.com/0AfwNSo.png) 是不是跟greedy algorithm中的 --- Interval Scheduling有關係啊? ## Heavy Hit ![](https://i.imgur.com/lkKZdHs.png) :::success # Shortest Path - Change Edge's Weight ::: ## Linear Scale Up ![](https://i.imgur.com/09Jd5L4.png) ## Quadratic Scale Up ![](https://i.imgur.com/HEidWyl.png) :::success # Modified Bellhamn ::: ## Equal in Relaxation => No shortrst Path Tree ### Shortrst Path Tree not exist but weight do ![](https://i.imgur.com/lJXIQiB.png) ### Exapmple ![](https://i.imgur.com/CJmB5jV.png) ## Not relaxed all edges at each iteration with the help of LEVEL build by BFS ![](https://i.imgur.com/KqH9RMr.png) :::success # Modified Dijkstra with ==lower degree== graph ::: :::info ## Lower Degree => ==$E=O(V)$== ::: ## Dijkstra Related – Insertion After Relaxation ### Why not Insertion Firstly? ###### tags: `relaxation` >For __SpeedUp__ >Complexity depend on ==(# of vertex in the priority queue)== #### 最近的K個點 = Extract-min K 次 ![](https://i.imgur.com/XUbn4we.png) ### Lower Dijkstra complexity if degree of each vertex is limited - ==$O(V\log V)$== ![](https://i.imgur.com/PWPYxSI.png) 原本把minimum edge weight理解成total的,後來才知道是單一的 假設有很多條path可以從s到t,我們會選 ref : https://www.quora.com/What-is-the-maximum-bottleneck-s-t-path-in-the-context-of-maximum-flow# ## SpeedUp using d-ary HEAP ### [SEE THIS FOR d-ary heap](https://hackmd.io/o5MDVxCtST24_F-7MCPwug#d-ary-HEAP) ![](https://i.imgur.com/qusqrLg.png) ![](https://i.imgur.com/6UogdOa.png) ![](https://i.imgur.com/E5QUe68.png) :::success # Cut Vertex(Articulation Point) ::: ###### tags: `Cut Vertex` ## Some property ### In undirected graph #### leaf cannot be a Articulation Point ![](https://i.imgur.com/VQZr6H5.png) #### root only has one child cannot be Articulation Point ![](https://i.imgur.com/tC5OFE4.png) has more than one child can be Articulation Point ![](https://i.imgur.com/zrOKTNg.png) #### a non-leaf, non-root node could be Articulation Point if not any back edge from a descendent to an ancestor in its DFS tree. ![](https://i.imgur.com/Il6amOr.png) ## How to check is connected ? ![](https://i.imgur.com/nJPyMe0.png) ## Brute Forece Way to Find Articulation Point -==$O(V(V+E))$== ![](https://i.imgur.com/isgrf3r.png) ## Property ![](https://i.imgur.com/SqxjQEC.jpg) ## Algorithm - ==low function== && ==discovery time== in DFS tree ![](https://i.imgur.com/VGDCITp.png) :::success # Cut Edge ## [SEE THIS](https://stellar.mit.edu/S/course/6/sp16/6.006/courseMaterial/topics/topic2/resource/pset4sols/pset4sols.pdf) ::: ###### tags: `Cut Edge` ## ## ==low function== && ==discovery time== in DFS tree ![](https://i.imgur.com/VCri7Fy.png) ## 不太懂 ![](https://i.imgur.com/LigqTrn.png) ## 在MINIMUNM SPANNING TREE中常用到 :::success # Bottleneck Problem ::: ###### tags: `relaxation` 有分兩種 ## ++Min-Max++ Bottleneck Problem - __The ==Maximum== weight of any edge in P is ==Minimize== among all P__ ### Dijkstra #### Step 1 : Initialization d[v] = infinity for v != s d[s] = negative infinity; #### Step 2 : Extract-==Min== #### Step 3 : Relaxation ##### Version 1 ```python== def relaxtion(u,v,w): d[v] = min(d[v],max(d[u],w)) ``` ##### Version 2 ```python== def relaxtion(u,v,w): if d[v] > max(d[u],w): d[v] = max(d[u],w) pre[v] = u ```` ![](https://i.imgur.com/ta1IbUK.png) ## ++Max-Min++ Bottleneck Problem - __The ==Minimum== weight of any edge in P is ==Maximize== among all P__ ### Dijkstra #### Step 1 : Initialization d[s] = infinity; d[v] = negative infinity for v != s #### Step 2 : Extract-==Max== #### Step 3 : Relaxation ##### Version 1 ```python== def relaxtion(u,v,w): d[v] = max(d[v],min(d[u],w)) ``` ##### Version 2 ```python== def relaxtion(u,v,w): if d[v] < min(d[u],w): d[v] = min(d[u],w) pre[v] = u ```` ## ==Max-Min== Bottleneck Problem ### Using Modifed Dijkstra Algorithm >See Above ![](https://i.imgur.com/Ty0N9cF.png) ### Not Be Affected By Modifed Dijkstra Algorithm - O(VLogV+E) ![](https://i.imgur.com/iko3SkH.png) >Note ![](https://i.imgur.com/tpWi0o9.png) ###### tags: `Prim Algorithm` ### [Building Block]At Least Certain Edge Weight in Graph ![](https://i.imgur.com/1nQhb1T.png) ### Using Binary Search with above Building Block - O(log(E)*(V+E)) ![](https://i.imgur.com/F6X4GEA.png) > Notice How to apply binary search to ==Max-Min== Problem > __==Min-Max==__ will be contray ![](https://i.imgur.com/Ay23Qft.png) ###### tags: `Binary Search` ## [Similar Technique]Shortest Path with least edge ###### tags: `relaxation` ![](https://i.imgur.com/tP6aUTY.png) ### ==Modified Relaxation== ![](https://i.imgur.com/IpkYul8.png) Counting sort is efficient if K≅n. :::success # Edge Weight = (0,1], Find Maximum Product ::: ## Proabiliry Of ==EDGE== Droping Packet ![](https://i.imgur.com/Pk52WMI.png) ## Proabiliry Of ==Vertex== Droping Packet ![](https://i.imgur.com/hlSjtBh.png) :::success # Negative Weight ::: ## [Trick] Still Terminate! ![](https://i.imgur.com/1TMg8P1.png) ## ==Exactly One Negative Weight== ![](https://i.imgur.com/4up8MyK.png) :::success # Two-way Shortest Path ::: ## Bi-directional shortest path using Dijkstra ### 終止條件:非相遇點, Counter-example。而是 ==$d_s[x]+d_t[x]$== ![](https://i.imgur.com/uDfs2Rd.png) ### Algorithm ![](https://i.imgur.com/ElA4UCG.png) ## Find common vertex in the two different shortest path tree ![](https://i.imgur.com/7TWKT7L.png) ## $V_c$ in shortest path <=> $d[s,V_c]+$==$d[V_c,t]$==$=d[s,t]$ step 1 : run 4 Dijkstra - 1. run Dijkstra rooted at s - 2. run Dijkstra rooted at u - 3. run __reverse__ Dijkstra rooted at t - 4. run __reverse__ Dijkstra rooted at v >因為要算 ==$d[V_c,t]$== 所以才reverse step 2 : iterate all vertex ![](https://i.imgur.com/B38ZnBq.png) ## Can ==only== set one edge weight to 0, find shortest path ### [Method 2](https://hackmd.io/h1SAF0J5S-C5CvKc5IIYAA?both#Star-Power---Only-1-Free-Weight-At-You-Please) ![](https://i.imgur.com/xVk9zrJ.png) ## One-Way BFS vs Two-Way BFS ![](https://i.imgur.com/DdL0UcF.png) ## Bi-directional BFS scenario ![](https://i.imgur.com/dmxviOj.png) ## Bi-directional BFS > run two bfs > - one with $G$ > - one with $G^T$ ![](https://i.imgur.com/bJeDO2E.png) ### Solution >別忘了,還要跟原本的比較 #### Way 1 : Naive Way - ==$O(E^{'}(V+E))$== #### Way 2 : Two-way BFS with one normal and one on transpose of original graph - ==$O(2(V+E)+E^{'})$== ![](https://i.imgur.com/mzu9UI6.png) ## Want to stop at specific but don't want to add too mych cost ![](https://i.imgur.com/1Fg49H1.png) ## ==Next== Minimum Shortest Path :::success Next : 第二小的 ::: ###### tags: `modified Dijkstra` ### ==Notice how it modify Dijkstra== ![](https://i.imgur.com/RmRwdGr.jpg) ### First shortest path跟 Next shortest path有兩種關係 #### Case 1 : 有部份重疊 當移掉first shortest path任一個edge就可以馬上找到next shortest path #### Case 2 : 完全沒有重疊 要移掉first shortest path中沒有重疊的一段sub path中的任一個edge 才會找到next shortest path __Case 2 example__ ![](https://i.imgur.com/HlyDxKt.png) ## ==Next== Minimum Shortest Path in DAG at ++each++ point ![](https://i.imgur.com/IhZOSDp.png) ## Longest Path and each path with positive distance ![](https://i.imgur.com/R17hGsK.png) ![](https://i.imgur.com/Hmq4OVh.png) ![](https://i.imgur.com/FUSIsy0.png) ![](https://i.imgur.com/npGQY4v.png) ![](https://i.imgur.com/Y8fC5U2.png) :::success # Edge Type ::: ### From Parent/Child View ![](https://i.imgur.com/FIfghmj.png) ### From Color View ![](https://i.imgur.com/fEoJxKp.png) ## In UNDIRECTED graph, No cross edge / forward edge(=block edge) ------------ ### 不是只有Parent /Child關係 => ==cross edge== ![](https://i.imgur.com/hv2P638.png) ## Different Tree Edge when choosing Different vertex as source :::info ### 不同的起始點選擇,會使得edge的性質變得不一樣 ::: ![](https://i.imgur.com/pEj5OPh.png) ## ==Singly Connected== - no cross/forward edge ### no need maintain $visited$ at each node when doing DFS ![](https://i.imgur.com/vmbWe6V.png) ## ==Remove Back Edge <--> Acyclic== ![](https://i.imgur.com/16dGmEJ.png) ## Number Of Cycles < Number Of Black Edge ![](https://i.imgur.com/yfhpbb4.png) ## Remove Found ONE Back Edge doesn't mean only ONE edge ![](https://i.imgur.com/v4zEtRZ.png) ## Given a topological order, is there always a DFS traversal that produces such an order? >從尾端做到頭部,每個DFS traversal tree都只有一個item ![](https://i.imgur.com/KlkTyLV.png) ## Generation of ==ALL== cross edge and no ++tree edge++ by using DFS > DFS 可以都沒有 tree edge ![](https://i.imgur.com/GZQgZkA.png) ## If it's a tree, then no ==back==/cross/forward edge ==> no need $parent$ in DFS :::danger 如果每個node只有一個incoming node的話,那可以不用紀錄node是否被visited過 ::: ![](https://i.imgur.com/n3Nhqdc.png) ## Turn a mixed graph to a directed graph without bringing cycle ###### tags: `topological sort` ![](https://i.imgur.com/3pEBJTf.png) :::success # Adjacent Matrix Multiplication ::: ## Square of Adjacent Matrix ![](https://i.imgur.com/OvmgLGM.png) ### Solution ![](https://i.imgur.com/HKIbdpH.png) ![](https://i.imgur.com/3zhGSuf.png) ## [General Case]Only go ==5== edge at a time ![](https://i.imgur.com/qAYLtPW.jpg) ## [More General Case]Transititve Clousure/Floyd–Warshall algorithm ###### tags: `Floyd–Warshall algorithm`,`Transititve Clousure` ### Transititve Clousure ![](https://i.imgur.com/CiOANyo.png) ![](https://i.imgur.com/XwFQyXc.png) ![](https://i.imgur.com/l26SzpS.png) ![](https://i.imgur.com/MVbjtti.png) :::success # Belllman-Ford ::: ## Complexity - ==$|V|(\sum_{for\ all\ vertex}O(out-degree) )$== ### Adjacent Matrix - $|V|^3$ ### Adjacent List - $|V||E|$ ## In 2 different view ### Way 1 : Outer loop is ==|V|==, Inner loop is ==|E|== ![](https://i.imgur.com/dgATnfO.png) ### Way 2 : Outer loop is ==|V|-1==, Inner loop is ==|V|== ![](https://i.imgur.com/RFFdoOP.png) ## Minimum Target = RoundTrip ![](https://i.imgur.com/Terme96.png) :::success # Dynamic Programming to Shortest Path ::: ## See [stanford slide](https://web.stanford.edu/class/archive/cs/cs161/cs161.1138/lectures/18/Small18.pdf) ## Bellman-Ford Solved By DP in 2 Ways ![](https://i.imgur.com/kwrMjpc.png) ## Floyd-Warshall Algorithm ### 看起來跟Bellhman Ford的dp形式很像,但其實有本質上的差異 #### Bellman Ford - (o) increasing the number of edges in the path #### Floyd-Warshall - (x) increase the set of vertices we allow as intermediate nodes in the path ## Belllman-Ford At Most ==K== edges ![](https://i.imgur.com/9hVNxNH.png) ## [Bellman Ford]Shortest path with ~~exactly~~ ++at most++ $k$ edges :::info 比較 __"[Pass through exactly k vertex](https://hackmd.io/h1SAF0J5S-C5CvKc5IIYAA?view#Pass-through-exactly-k-vertex )"__ ::: ![](https://i.imgur.com/FbUur2Z.png) ### number of subprobelm $O(kV)$ ![](https://i.imgur.com/UKkF0SJ.png) ### Recurrsion of DP ![](https://i.imgur.com/3fwaLDw.png) ### Complexity of each subproblem - $O(V)$ ![](https://i.imgur.com/8CeQvpu.png) ### Toal Complexity : $O(kE)$ ![](https://i.imgur.com/nYomAsM.png) ## ==[??]== Short Path under Budget ![](https://i.imgur.com/VVEvoPq.png) ## Pass through exactly k vertex ## ==[Concept]== 從vertex i 到 vertex j 且長度為k,有++幾種走法++? ![](https://i.imgur.com/TatIwWy.png) :::success # Maximum Length Of A Graph ::: ## Maximum Length DFS Could Pass ![](https://i.imgur.com/rD9vwap.png) ## Maximum Total Length Given Weight ![](https://i.imgur.com/i3j4tyJ.png) :::success # Cycle ::: ## Check for ==No Odd Cycles(Bipartite)== ![](https://i.imgur.com/J8UCqpZ.png) ### Solution ![](https://i.imgur.com/roVDwPC.png) ---- ### ++Lemma : A graph does not contain odd cycles if and only if it is bipartite++ ![](https://i.imgur.com/ay2bCFU.png) ![](https://i.imgur.com/QAYazWO.png) #### it is bipartite ==-->== A graph does not contain odd cycles ![](https://i.imgur.com/LljiZCY.png) #### [比較難想]it is bipartite ==<--== A graph does not contain odd cycles >用反證法 :!(it is bipartite) ==-->== !(A graph does not contain odd cycles) ![](https://i.imgur.com/4LDvwsi.png) ![](https://i.imgur.com/BarC3Ni.png) #### Note : Checking Bipartite = whether the graph is 2-colorable ---- ## Can use Belllman-Ford to detect ==positive== cycle >Belllman-Ford原本只能用來detect ==negative== __cycle__ >但可以透過negate weight的方式,來detect ==positive== cycle ![](https://i.imgur.com/VIrGGN8.png) ## ==[??]== Given negative cycle, Label each vertex ![](https://i.imgur.com/62Led1n.png) ## Negative Cycle - Arbitage ### Need an extra node as a start node, then add edge from start node to each other nodes ![](https://i.imgur.com/bE5sMWk.png) ### Print all negative cycle ![](https://i.imgur.com/CbYTde3.png) :::success # Other Application/Property ::: ## Only 1 Shortest Distance, but not Shortest Path ![](https://i.imgur.com/4wVHHIR.png) ## BFS Level ![](https://i.imgur.com/YfRfIWB.png) ![](https://i.imgur.com/KbFrKnt.png) ## Unversial Sink ![](https://i.imgur.com/CMGl4yt.jpg) ## Minimum Vertex ![](https://i.imgur.com/mzKjUpf.png) ![](https://i.imgur.com/ALbEQRj.png) ![](https://i.imgur.com/rFSAdcJ.png) ## Diameter Of A GRAPH ![](https://i.imgur.com/SMAJvcQ.png) ### ==[??]== ![](https://i.imgur.com/HgP4VNO.png) ## Dynamic Programming BFS/DFS ![](https://i.imgur.com/kmVHijh.png) ### Connected Component ![](https://i.imgur.com/lpZMqbK.png) ## Better choice for dynamical graph : Adajacent Matrix ![](https://i.imgur.com/HziKkLx.png) ## 總是有方法可以把undirected變成DAG ![](https://i.imgur.com/TsGUdz2.png) ## Triangle property ![](https://i.imgur.com/ZDO1RF4.png) ## ==[??]== ### ![](https://i.imgur.com/AQTpwMB.png) ### 2009 q2 ![](https://i.imgur.com/414wQZV.png) ## Subproblem dependency graph ![](https://i.imgur.com/YWjzS8M.png) ## DFS and Hamiltonian ![](https://i.imgur.com/C53EWuV.png) ## DFS is more deep than BFS ![](https://i.imgur.com/L9UuMww.png) ## No back edge in BFS doesn't mean acyclic ![](https://i.imgur.com/tfHqOz2.png) :::success # Minimum Spanning Tree ::: ###### tags: `low degree` ## Each vertex with degree = 2 ![](https://i.imgur.com/50v9tSa.png) ## Lightest and second lightest are in MST ![](https://i.imgur.com/PRdcRUY.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully