#define ll long long #define mp make_pair #define ALL(x) x.begin(), x.end()
constint mod = 1e9 + 7;
vector<vector<int>> ver; vector<int> vis;
intdfs(int x, int start = 0) { if (vis[x]) return0; if (!start) vis[x] = 1; int res = 1; for (int i = 0; i < ver[x].size(); i++) res += dfs(ver[x][i]); return res; }
voidsolve(int v) { ver.clear(); ver.resize(v + 1); int temp, t1; while (cin >> temp && temp) { while (cin >> t1 && t1) ver[temp].emplace_back(t1); } int m; cin >> m; for (int i = 0; i < m; i++) { vis.clear(); vis.resize(v + 1, 0); cin >> temp; cout << v + 1 - dfs(temp, 1); for (int j = 1; j <= v; j++) { if (vis[j] == 0) cout << " " << j; } cout << "\n"; } }
intmain(int argc, constchar *argv[]) { int v; while (cin >> v && v) solve(v); return0; }
brute force = TLE Therefore, we think that if we had traveled the vertex before, we donβt have to travel it again, since if it has been traversed, the traveler is definitely possessed greater reachable person.
voidsolve() { int m; cin >> m; memset(v, 0, m + 1); for (int i = 0; i < m; i++) { int ind; cin >> ind; cin >> v[ind]; } int res = 0, idx; memset(vis, false, m + 1); for (int i = 1; i <= m; i++) { if (!vis[i]) { memset(dfsV, false, m + 1); int temp = dfs(i); if (res < temp) { res = temp; idx = i; } } } cout << idx << endl; }
intmain(int argc, constchar *argv[]) { fast; int t; cin >> t; for (int i = 0; i < t; i++) { cout << "Case " << i + 1 << ": "; solve(); }