Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day 24, 25 py #80

Merged
merged 5 commits into from
Dec 25, 2023
Merged

day 24, 25 py #80

merged 5 commits into from
Dec 25, 2023

Conversation

RongkunWang
Copy link
Collaborator

@RongkunWang RongkunWang commented Dec 25, 2023

day 24..

also day 25:
using many help from https://www.reddit.com/r/adventofcode/comments/18qbsxs/2023_day_25_solutions/, wikipedia and google.

The maximum flow of the graph between two vertices from the two subgraphs is 3. So there are 3 paths beteween any two vertices of the two graph.
So I start to find the path between 0th vertex and another vertex V=1, using BFS, and remove all edges in each path. I did it 3 times to find the 3 flows. if there's only 3 flows, the two V are disconnected. This means they are in their own subgraph. Solution found. If more flows are find, they're on the same subgraph and just consider V+=1 until solution is found. Similar to https://www.reddit.com/r/adventofcode/comments/18qbsxs/comment/keue5sc/?utm_source=share&utm_medium=web2x&context=3

This is a special case of Edmonds-Karp algorithm for solving maximum flow with capacity of 1 for each edge. The removal of edge in the above algorithm after one path found is the same as increasing the edge flow from 0 to 1 and thus preventing the next path to consider the same edge.
I didn't implement the alg for finding the actual cuts, and many other people don't. All the edges removed are a superset of the three edges that actually need to be removed. And the extra edges doesn't affect the result, by creating more subgraphs. Why?

I think I'm just luky that the topology don't have some special scenario..

@RongkunWang
Copy link
Collaborator Author

@Moelf how to install numpy for our ci?

@Moelf
Copy link
Owner

Moelf commented Dec 25, 2023

I guess you can just run a pip install command in the CI, numpy is fast to install

@Moelf Moelf mentioned this pull request Dec 25, 2023
@RongkunWang RongkunWang marked this pull request as draft December 25, 2023 18:20
@RongkunWang
Copy link
Collaborator Author

I constructed this input and indeed the result is not correct.

abc: edf ghi klm nop qrs tuv jjj mmm nnn                                                                                                                            
edf: ghi klm bbb
ghi: klm bbb
klm: bbb
jjj: mmm nnn bor
mmm: nnn bos
nnn: bot
nop: qrs tuv ccc
qrs: tuv ccc
tuv: ccc
bbb: bor bos bot
ccc: bor bos bot
bor: cor
bos: cos
bot: cot
cor: end enf
cos: end enf
cot: end enf
end: enf

So I improved the algorithm following exactly the golang, categorizing every single node. and it is now properly done.

@RongkunWang RongkunWang marked this pull request as ready for review December 25, 2023 19:29
@Moelf
Copy link
Owner

Moelf commented Dec 25, 2023

You can merge it whenever. Idk how you want to squash or not

@RongkunWang RongkunWang merged commit d694b5e into main Dec 25, 2023
1 check passed
@RongkunWang RongkunWang deleted the rk/py branch December 25, 2023 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants