結果

問題 No.2900 Star Divine
ユーザー vjudge1
提出日時 2024-09-26 10:32:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 200,932 KB
最終ジャッジ日時 2025-02-24 12:45:52
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAXN = 100001;

int t, n[2], m, in[MAXN], res;
bool vis[MAXN];
vector<int> e[MAXN], ans;

void Solve() {
  cin >> n[0] >> n[1] >> m;
  for(int i = 1; i <= n[0]; ++i) {
    vis[i] = in[i] = 0;
  }
  for(int i = 1; i <= n[1]; ++i) {
    e[i].clear();
  }
  for(int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    e[v].emplace_back(u);
  }
  for(int i = 1; i <= n[1]; ++i) {
    sort(e[i].begin(), e[i].end());
    e[i].erase(unique(e[i].begin(), e[i].end()), e[i].end());
    for(int v : e[i]) {
      in[v]++;
    }
  }
  ans.clear();
  for(int i = 1; i <= n[1]; ++i) {
    int cnt = 1;
    for(int v : e[i]) {
      cnt += (in[v] == 1) * (vis[v] ? -1 : 1);
      in[v]--;
    }
    if(cnt >= 0) {
      ans.emplace_back(i);
      for(int v : e[i]) {
        vis[v] ^= 1;
      }
    }
  }
  res = 0;
  for(int i = 1; i <= n[0]; ++i) {
    res += vis[i];
  }
  cout << res << " " << ans.size() << "\n";
  for(int i = 1; i <= n[0]; ++i) {
    if(vis[i]) {
      cout << i << " ";
    }
  }
  cout << "\n";
  for(int x : ans) {
    cout << x << " ";
  }
  cout << "\n\n";
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for(cin >> t; t--; Solve()) {
  }
  return 0;
}
0