Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaba953b

Browse files
authored
Small changes in code
1 parentb1e07e8 commitaba953b

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)

[8]ページ先頭

©2009-2025 Movatter.jp