Created
June 4, 2018 15:24
-
-
Save jianminchen/c7f41031efe0429ca3fcb0216d1a46e4 to your computer and use it in GitHub Desktop.
This file contains 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
A B = 5 | |
B D = 6 | |
C D = 3 | |
E F | |
F G | |
| | |
? D | |
A B | |
a - c - b - d | |
a -> c | |
a/b = a/c / b/c | |
a/d = a/b / b/d | |
a a = 1 | |
a b = ? | |
a c => a/b b/c | |
a d => a/b b/d | |
a is the center point | |
c - a | |
b - a | |
d - a | |
? a | |
b c | |
steps: | |
(1) build graph (n) | |
(2) find connected components (n) | |
(3) for every component: (n) | |
find a center point x | |
convert their relationships to ? - x | |
(4) query: x, y (1) | |
x and y are not in the same com: return -1 | |
else: | |
x or y is the center point, return v, 1/v | |
x/c, y/c -> x/y | |
A-B-D-C -> | |
E-F-G | |
O(3*N) + O(M) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment