|
|
back to boardPlease, help WA5! Here's my wrong solution, can sb view the code and help me? #include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> pos; vector<vector<int>> in; vector<vector<int>> out; vector<int> ans; void lets_go(int i) { for (int j = 0; j < in[i].size(); j++) { if (pos[in[i][j]] == 0) { lets_go(in[i][j]); } } pos[i] = 1; ans.push_back(i); for (int j = 0; j < out[i].size(); j++) { if (pos[out[i][j]] == 0) { lets_go(out[i][j]); } } } int main() { int n; cin >> n; in.resize(n); out.resize(n); pos.resize(n, 0); for (int i = 0; i < n; i++) { int a; cin >> a; while (a != 0) { if (a != 0) { in[a - 1].push_back(i); out[i].push_back(a - 1); cin >> a; } } } for (int i = 0; i < n; i++) { if (pos[i] == 0) { lets_go(i); } } for (int i = 0; i < n; i++) { cout << ans[i] + 1 << " "; } } |
|
|