|
|
back to boardwhat's wrong? what's wrong with this code: #include <iostream> #include <vector> #include <list> using namespace std; int ar[102][102],viz[102]; int n; list <int> a; int dfs(int s) { viz[s] = 1; for (int i=1;i<=n;i++) { if (ar[i][s] && !viz[i]) {dfs(i); }//a.push_back(i);} } return 0; } int main() { cin >> n; int z; for (int i=1;i<=n;) { cin >> z; if (z == 0) i++; else ar[i][z] = 1; } dfs(1); for (int i=1;i<=n;i++) if(!viz[i]) a.push_back(i); cout << a.size() << endl; for (int n : a) { cout << n << " "; } return 0; } maybe i didn't understand problem properly,some help? |
|
|