結果

問題 No.2900 Star Divine
ユーザー lmxyue
提出日時 2025-08-26 18:33:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 201,496 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-26 18:33:28
合計ジャッジ時間 4,981 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAXN = 100001;

int t, n[2], m, ans, ans2;
mt19937_64 rnd(time(0));
bool vis[MAXN], vis2[MAXN];
vector<int> e[MAXN];

bool check() {
  int cnt = 0;
  for(int i = 1; i <= n[0]; ++i) {
    vis2[i] = 0;
  }
  for(int i = 1; i <= n[1]; ++i) {
    vis[i] = rnd() % 2;
    cnt += vis[i];
    if(vis[i]) {
      for(int v : e[i]) {
        vis2[v] ^= 1;
      }
    }
  }
  for(int i = 1; i <= n[0]; ++i) {
    cnt += vis2[i];
  }
  return cnt >= (n[0] + n[1] + 1) / 2;
}

void Solve() {
  cin >> n[0] >> n[1] >> m;
  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(; !check(); ) {
  }
  ans = ans2 = 0;
  for(int i = 1; i <= n[0]; ++i) {
    ans += vis2[i];
  }
  for(int i = 1; i <= n[1]; ++i) {
    ans2 += vis[i];
  }
  cout << ans << " " << ans2 << "\n";
  for(int i = 1; i <= n[0]; ++i) {
    if(vis2[i]) {
      cout << i << " ";
    }
  }
  cout << "\n";
  for(int i = 1; i <= n[1]; ++i) {
    if(vis[i]) {
      cout << i << " ";
    }
  }
  cout << "\n\n";
}

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