QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283809#7738. Equivalent Rewritingckiseki#RE 0ms3596kbC++202.0kb2023-12-15 15:28:462023-12-15 15:28:46

Judging History

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

  • [2023-12-15 15:28:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3596kb
  • [2023-12-15 15:28:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define orange(a...) orange_(#a, a)
#define debug(a...) debug_(#a, a)
#include <experimental/iterator>
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m; 
    vector<int> res(m, -1);
    vector<vector<int>> ops(n);
    for (auto &op : ops) {
      int l;
      cin >> l;
      op.resize(l);
      for (int &p : op) {
        cin >> p;
        p -= 1;
      }
    }
    for (int i = 0; i < n; ++i) {
      for (auto p : ops[i])
        res[p] = i;
    }

    vector<int> ind(n + m);
    vector<vector<int>> g(n + m);
    auto add_edge = [&](int u, int v) {
      g[u].push_back(v);
      ind[v]++;
    };
    for (int i = 0; i < n; ++i) {
      for (int p : ops[i]) {
        if (res[p] == i) {
          add_edge(res[p] + n, i);
        } else {
          add_edge(i, res[p] + n);
        }
      }
    }
    
    vector<int> ans;
    priority_queue<int> bfs;
    for (int i = 0; i < n + m; ++i) {
      if (ind[i] == 0)
        bfs.push(i);
    }
    while (not bfs.empty()) {
      int u = bfs.top();
      bfs.pop();
      if (u < n) {
        ans.push_back(u + 1);
      }
      for (int v : g[u]) {
        if (--ind[v] == 0)
          bfs.push(v);
      }
    }
    if (ranges::is_sorted(ans)) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
      for (int i = 0; i < n; ++i)
        cout << ans[i] << " \n"[i + 1 == n];
    }
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

Yes
3 1 2
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Runtime Error

input:

1
10 5
2 2 4
4 1 3 4 2
1 2
3 2 1 4
4 5 2 4 3
3 2 5 4
3 5 4 2
3 1 3 2
5 1 4 2 3 5
1 4

output:


result: