54082023-05-13 10:28:55TomaSajtKritikus munkákcpp17Wrong answer 50/10093ms28648 KiB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> g;
vector<int> d, l;
set<int> res;

int t = 0;

void dfs(int u) {
  d[u] = l[u] = ++t;
  for (auto &v : g[u]) {
    if (d[v]) {
      l[u] = min(l[u], d[v]);
      continue;
    }
    dfs(v);
    l[u] = min(l[u], l[v]);
    if (l[v] >= d[u]) res.insert(u);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  g.resize(n + 2), d.resize(n + 2), l.resize(n + 2);
  vector<int> in_deg(n + 1), out_deg(n + 1);
  while (m--) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v), g[v].push_back(u);
    out_deg[u]++, in_deg[v]++;
  }
  for (int i = 1; i <= n; i++) {
    if (in_deg[i] == 0) g[0].push_back(i), g[i].push_back(0);
    if (out_deg[i] == 0) g[n + 1].push_back(i), g[i].push_back(n + 1);
  }
  dfs(0);

  res.erase(0), res.erase(n + 1);
  cout << res.size() << '\n';
  for (auto &r : res) cout << r << ' ';
  return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted57ms13376 KiB
subtask225/25
3Accepted57ms13376 KiB
4Accepted2ms2128 KiB
5Accepted3ms2400 KiB
6Accepted3ms2688 KiB
7Accepted3ms2684 KiB
8Accepted4ms3076 KiB
subtask325/25
9Accepted4ms3076 KiB
10Accepted16ms5664 KiB
11Accepted8ms4312 KiB
12Accepted8ms4440 KiB
13Accepted12ms5120 KiB
14Accepted12ms5052 KiB
subtask40/25
15Accepted12ms5052 KiB
16Accepted48ms16236 KiB
17Wrong answer46ms15272 KiB
18Wrong answer45ms15472 KiB
19Wrong answer45ms16180 KiB
20Wrong answer45ms16464 KiB
subtask50/25
21Wrong answer45ms16464 KiB
22Wrong answer89ms25868 KiB
23Wrong answer93ms26312 KiB
24Wrong answer92ms26364 KiB
25Wrong answer89ms26968 KiB
26Wrong answer86ms28648 KiB