fork download
  1. //Done by: K Ashwin
  2.  
  3. #include<bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. typedef pair<int, int> pii;
  9.  
  10. #define REP(i, a, b) \
  11. for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
  12. #define TR(c, it) \
  13. for (auto it = (c).begin(); it != (c).end(); it++)
  14.  
  15. #define s(x) scanf("%d", &x)
  16. #define sl(x) scanf("%lld", &x)
  17. #define pb push_back
  18. #define mp make_pair
  19. #define fi first
  20. #define se second
  21. #define set0(a) memset(a, 0, sizeof(a))
  22. #define setdp(a) memset(a, -1, sizeof(a))
  23. #define INF 2000000000
  24. #define MOD 1000000007
  25.  
  26. vector <int> adj[20005], ra[20005], v, ans;
  27. int vis[20005], in[20005];
  28.  
  29. void dfs(int cur)
  30. {
  31. vis[cur] = 1;
  32.  
  33. TR (adj[cur], it) {
  34. if (!vis[*it])
  35. dfs(*it);
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. int t, n, qu, k, x, y, cur;
  42.  
  43. cin >> t;
  44.  
  45. while (t--) {
  46. cin >> n >> qu;
  47.  
  48. REP (i, 1, n) {
  49. adj[i].clear();
  50. ra[i].clear();
  51. }
  52.  
  53. set0(vis);
  54. set0(in);
  55.  
  56. REP (i, 1, n) {
  57. s(k);
  58.  
  59. REP (j, 1, k) {
  60. s(x);
  61.  
  62. adj[i].pb(x);
  63. ra[x].pb(i);
  64. in[i]++;
  65. }
  66. }
  67.  
  68. v.clear();
  69.  
  70. REP (i, 1, qu) {
  71. s(x);
  72.  
  73. v.pb(x);
  74. }
  75.  
  76. TR (v, it)
  77. if (!vis[*it])
  78. dfs(*it);
  79.  
  80. priority_queue <int, vector <int>, greater <int> > pq;
  81.  
  82. while (!pq.empty())
  83. pq.pop();
  84.  
  85. REP (i, 1, n) {
  86. //cout << i << " " << vis[i] << " " << in[i] << endl;
  87. if (vis[i] && !in[i])
  88. pq.push(i);
  89. }
  90.  
  91. ans.clear();
  92. while (!pq.empty()) {
  93. cur = pq.top();
  94. pq.pop();
  95.  
  96. ans.pb(cur);
  97.  
  98. TR (ra[cur], it) {
  99. in[*it]--;
  100. if (!in[*it] && vis[*it])
  101. pq.push(*it);
  102. }
  103. }
  104.  
  105. cout << ans.size() << endl;
  106. TR (ans, it)
  107. cout << *it << " ";
  108. cout << endl;
  109. }
  110.  
  111. return 0;
  112. }
  113.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError:   File "prog.py", line 1
    //Done by: K Ashwin
     ^
SyntaxError: invalid syntax

stdout
Standard output is empty