QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#273777#7107. Chaleurikaurov#TL 0ms3428kbC++201.3kb2023-12-03 04:01:152023-12-03 04:01:15

Judging History

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

  • [2023-12-03 04:01:15]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3428kb
  • [2023-12-03 04:01:15]
  • 提交

answer

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define all(arr) (arr).begin(), (arr).end()
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define endl '\n'

void solve(){
  int n, m;
  cin >> n >> m;
  set<pair<int, int>> edges;
  vector<int> order(n), deg(n + 1);
  while (m--){
    int x, y;
    cin >> x >> y;
    edges.insert({x, y});
    edges.insert({y, x});
    deg[x]++, deg[y]++;
  }
  iota(all(order), 1);
  sort(all(order), [&] (int i, int j){
    return deg[i] > deg[j];
  });
  int sz = 0;
  while (sz < n){
    int v = order[sz];
    bool good = 1;
    for (int i = 0; i < sz; i++) good &= edges.count({order[i], v});
    if (!good) break;
    sz++;
  }
  int x = 1, y = 0;
  for (int i = 0; i < n; i++){
    int v = order[i];
    if (i < sz) y += (deg[v] == sz - 1);
    else x += (deg[v] == sz - 1);
  }
  if (!y){
    y = 1;
    for (int i = 0; i < sz; i++){
      int v = order[i];
      y += (deg[v] == sz);
    }
  }

  cout << x << " " << y << endl;
}

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout.precision(20);
  int t;
  cin >> t;
  while (t--){
    solve();
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Time Limit Exceeded

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: