Skip to content

Conversation

weilycoder
Copy link
Contributor

@weilycoder weilycoder commented Dec 15, 2024

支持根据度数序列生成图。

import random
from cyaron.graph import *

random.seed(0, 2)

print(Graph.from_degree_sequence([2, 2, 1, 1, 1, 1]).to_str(output=Edge.unweighted_edge))
print()
print(Graph.from_degree_sequence([(1, 2), (1, 1), (1, 0)]).to_str(output=Edge.unweighted_edge))

根据输入度数序列的不同格式,会返回有向图或无向图。

上述代码输出:

1 2
1 5
2 6
3 4

1 2
1 3
2 1

还没写测试。

@weilycoder
Copy link
Contributor Author

随机的方法是先根据序列贪心地生成一张图,再随机打乱。

@Mr-Python-in-China
Copy link
Collaborator

@weilycoder 你看看 没问题就merge了

@weilycoder
Copy link
Contributor Author

weilycoder commented Feb 16, 2025

没啥问题吧 @Mr-Python-in-China

@Mr-Python-in-China Mr-Python-in-China merged commit 340c732 into luogu-dev:master Feb 16, 2025
4 checks passed
@weilycoder weilycoder deleted the dev-deg branch February 16, 2025 09:01
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