QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480749#906. 强连通分量mfeitveer#WA 3ms34568kbC++141.8kb2024-07-16 18:33:202024-07-16 18:33:20

Judging History

你现在查看的是最新测评结果

  • [2024-07-16 18:33:20]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:34568kb
  • [2024-07-16 18:33:20]
  • 提交

answer

/*
  ! 以渺小启程,以伟大结束。
  ! Created: 2024/07/16 17:22:45
*/
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define mp(x, y) make_pair(x, y)
#define eb(...) emplace_back(__VA_ARGS__)
#define fro(i, x, y) for (int i = (x); i <= (y); i++)
#define pre(i, x, y) for (int i = (x); i >= (y); i--)
inline void JYFILE19();

typedef long long i64;
typedef pair<int, int> PII;

bool ST;
const int N = 1e6 + 10;
const int mod = 998244353;

int n, m, ct, tp, tt, head[N];
int dn[N], lw[N], vs[N], st[N];
struct edge {
  int to, nxt;
} e[N << 1];
vector<int> to[N];

inline void add(int x, int y) {
  e[++ct] = {y, head[x]}, head[x] = ct;
}
inline void dfs(int x) {
  dn[x] = lw[x] = ++ct, vs[x] = 1, st[++tp] = x;
  for (int i = head[x]; i; i = e[i].nxt) {
    if (!dn[e[i].to]) {
      dfs(e[i].to);
      lw[x] = min(lw[x], lw[e[i].to]);
    } else if (vs[e[i].to]) {
      lw[x] = min(lw[x], dn[e[i].to]);
    }
  }
  if (dn[x] == lw[x]) {
    ++tt;
    while (st[tp + 1] != x) {
      to[tt].eb(st[tp]);
      vs[st[tp]] = 0;
      tp--;
    }
  }
}

signed main() {
  JYFILE19();
  cin >> n >> m;
  fro(i, 1, m) {
    int x, y;
    cin >> x >> y;
    x++;
    y++;
    add(x, y);
  }
  fro(i, 1, n)
    if (dn[i] == 0) dfs(i);
  cout << tt << "\n";
  fro(i, 1, tt) {
    cout << to[i].size() << " ";
    for (auto j : to[i])
      cout << j - 1 << " ";
    cout << "\n";
  }
  return 0;
}

bool ED;
inline void JYFILE19() {
  // freopen("", "r", stdin);
  // freopen("", "w", stdout);
  srand(random_device{}());
  ios::sync_with_stdio(0), cin.tie(0);
  double MIB = fabs((&ED-&ST)/1048576.), LIM = 512;
  cerr << "MEMORY: " << MIB << endl, assert(MIB<=LIM);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 34568kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
2 3 0 
1 2 
2 4 1 
1 5 

result:

wrong answer 5 is later than 2, but there is an edge (5, 2)