题解

李慕航  •  1小时前


include <bits/stdc++.h>

using namespace std;

bool vis[105] = {}; int tu[105][105]; queue q; int n, m = 0; void dfs(int t) {

vis[t] = 1;
if (m == 0) {
    cout << t;
    m = 1;
} else {
    cout << "-" << t;
}
for (int i = 1; i <= n; i++) {
    if (tu[t][i] == 1 && vis[i] == 0) {
        dfs(i);
    }
}

}

int main() {

cin >> n;
memset(vis, 0, sizeof vis);
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
        cin >> tu[i][j];
    }
}

dfs(1);
    

cout << endl;
return 0;

}


评论:

请先登录,才能进行评论