formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -8,44 +8,37 @@ vector<vector<int>> G;
vector<bool> visited;
vector<int> ans;
void dfs(int v)
{
void dfs(int v) {
visited[v] = true;
for (int u : G[v])
{
for (int u : G[v]) {
if (!visited[u])
dfs(u);
}
ans.push_back(v);
}
void topological_sort()
{
void topological_sort() {
visited.assign(n, false);
ans.clear();
for (int i = 0; i < n; ++i)
{
for (int i = 0; i < n; ++i) {
if (!visited[i])
dfs(i);
}
reverse(ans.begin(), ans.end());
}
int main()
{
int main() {
cout << "Enter the number of vertices and the number of directed edges\n";
cin >> n >> m;
int x, y;
G.resize(n, vector<int>());
for (int i = 0; i < n; ++i)
{
for (int i = 0; i < n; ++i) {
cin >> x >> y;
x--, y--; // to convert 1-indexed to 0-indexed
G[x].push_back(y);
}
topological_sort();
cout << "Topological Order : \n";
for (int v : ans)
{
for (int v : ans) {
cout << v + 1
<< ' '; // converting zero based indexing back to one based.
}