QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#159030#7107. Chaleurucup-team859#AC ✓134ms16208kbC++141.9kb2023-09-02 17:21:182023-09-02 17:21:19

Judging History

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

  • [2023-09-02 17:21:19]
  • 评测
  • 测评结果:AC
  • 用时:134ms
  • 内存:16208kb
  • [2023-09-02 17:21:18]
  • 提交

answer

#include <bits/stdc++.h>

#define lsb(x) (x & (-x))

using ull = unsigned long long;
using ll = long long;

using namespace std;

const int NMAX = 1e5 + 1;

vector<int> v[NMAX];

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    v[i].clear();

  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  int mx = 0, wh = 1;
  for (int i = 1; i <= n; ++i) {
    if ((int)v[i].size() > mx)
      mx = v[i].size(), wh = i;
  }

  vector<int> pot(n + 1, 0);
  int nr = 1;
  priority_queue<pair<int, int>> pq;
  for (auto it : v[wh]) {
    pot[it] = nr;
    pq.push({v[it].size(), it});
  }

  vector<int> c;
  c.push_back(wh);
  while (!pq.empty()) {
    int nod = pq.top().second;
    pq.pop();
    if (pot[nod] != nr)
      continue;

    ++nr;
    c.push_back(nod);
    for (auto it : v[nod]) {
      if (pot[it] == nr - 1)
        pot[it] = nr;
    }
  }

  vector<int> inc(n + 1, 0);
  int sx = 0;
  int a1 = 0;
  for (auto nod : c) {
    sx ^= nod;
    inc[nod] = 1;

    if (v[nod].size() == c.size() - 1)
      ++a1;
  }

  if (a1 > 1) {
    cout << 1 << " " << a1 << '\n';
    return;
  }

  if (a1 == 0) {
    a1 = 1;
    for (auto nod : c) {
      if (v[nod].size() == c.size())
        ++a1;
    }
  }


  int a2 = 1;
  for (int i = 1; i <= n; ++i) {
    if (inc[i])
      continue;

    int cnt = 0;
    int mis = sx;
    for (auto it : v[i]) {
      if (inc[it]) {
        ++cnt;
        mis ^= it;
      }
    }

    if (cnt == c.size() - 1) {
      ++a2;
    }
  }

  cout << a2 << " " << a1 << '\n';
}

int main() {
#ifdef HOME
  ifstream cin("input.in");
  ofstream cout("output.out");
#endif
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int t = 1;
  cin >> t;
  while (t--)
    solve();

  return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5928kb

input:

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

output:

2 1
1 4
1 2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 134ms
memory: 16208kb

input:

2231
1 0
5 7
4 1
3 4
3 1
3 5
4 2
3 2
4 5
5 4
2 1
2 5
2 4
2 3
5 10
3 2
2 5
1 4
4 2
4 5
1 2
1 3
3 5
3 4
1 5
5 10
1 3
2 4
1 4
5 2
2 3
1 5
5 4
1 2
3 4
5 3
5 9
2 5
3 5
2 3
2 1
4 3
3 1
4 1
4 5
2 4
5 4
4 2
4 1
4 5
4 3
5 9
4 1
4 5
3 4
2 4
2 1
3 1
2 5
3 5
3 2
5 4
2 5
2 3
2 1
2 4
5 9
5 2
1 3
4 3
1 2
5 4
4 2
5...

output:

1 1
3 1
4 1
1 5
1 5
2 1
4 1
2 1
4 1
2 1
2 1
3 1
4 1
4 1
1 5
2 1
4 1
1 5
1 5
1 5
3 1
4 1
4 1
4 1
3 1
3 1
4 1
4 1
2 1
4 1
4 1
1 5
1 5
2 1
4 1
4 1
4 1
3 1
2 1
4 1
2 1
4 1
4 1
4 1
3 1
1 5
4 1
4 1
1 5
2 1
4 1
2 1
2 1
1 5
4 1
1 5
3 1
4 1
1 5
2 1
1 5
3 1
3 1
1 5
3 1
3 1
2 1
1 5
4 1
3 1
1 5
2 1
3 1
2 1
2 1
...

result:

ok 2231 lines

Extra Test:

score: 0
Extra Test Passed