Skip to content

Commit aba953b

Browse files
authored
Small changes in code
1 parent b1e07e8 commit aba953b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/graph/euler_path.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,8 @@ int main() {
9898
ios::sync_with_stdio(0);
9999
cin.tie(0);
100100
int n, m;
101-
cin >> n >> m;
102-
edges.clear();
103-
g.assign(n, vector<int> ());
104-
used.assign(m + 1, false);
105-
res.clear();
106-
for (int i = 0; i < m; i++) {
107-
int u, v;
108-
cin >> u >> v;
109-
u--, v--;
110-
add_edge(u, v);
111-
}
101+
// reading the graph
102+
112103
int v1 = -1, v2 = -1;
113104
bool bad = false;
114105
for (int i = 0; i < n; i++) {
@@ -122,18 +113,24 @@ int main() {
122113
}
123114
}
124115
}
116+
125117
int first = 0;
126118
while (first < n && g[first].empty()) {
127119
first++;
128120
}
121+
129122
if (bad || (v1 != -1 && v2 == -1) || first == n) {
130123
cout << -1 << '\n';
131124
return 0;
132125
}
126+
133127
if (v1 != -1) {
134128
add_edge(v1, v2);
135129
}
130+
131+
used.assign((int) edges.size(), false);
136132
dfs(first);
133+
137134
if (v1 != -1) {
138135
for (int i = 0; i + 1 < (int) res.size(); i++) {
139136
if ((res[i] == v1 && res[i + 1] == v2) ||
@@ -150,12 +147,14 @@ int main() {
150147
}
151148
}
152149
}
150+
153151
for (int i = 0; i < n; i++) {
154152
if (!g[i].empty()) {
155153
cout << -1 << '\n';
156154
return 0;
157155
}
158156
}
157+
159158
for (int x : res) {
160159
cout << x + 1 << ' ';
161160
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy