QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163068#7107. Chaleurhos_lyricAC ✓190ms10124kbC++147.4kb2023-09-03 20:01:312023-09-03 20:01:31

Judging History

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

  • [2023-09-03 20:01:31]
  • 评测
  • 测评结果:AC
  • 用时:190ms
  • 内存:10124kb
  • [2023-09-03 20:01:31]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

// fast IO by yosupo
// sc.read(string &) appends the input
struct Scanner {
    FILE* fp = nullptr;
    char line[(1 << 15) + 1];
    size_t st = 0, ed = 0;
    void reread() {
        memmove(line, line + st, ed - st);
        ed -= st;
        st = 0;
        ed += fread(line + ed, 1, (1 << 15) - ed, fp);
        line[ed] = '\0';
    }
    bool succ() {
        while (true) {
            if (st == ed) {
                reread();
                if (st == ed) return false;
            }
            while (st != ed && isspace(line[st])) st++;
            if (st != ed) break;
        }
        if (ed - st <= 50) reread();
        return true;
    }
    template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
    bool read_single(T& ref) {
        if (!succ()) return false;
        while (true) {
            size_t sz = 0;
            while (st + sz < ed && !isspace(line[st + sz])) sz++;
            ref.append(line + st, sz);
            st += sz;
            if (!sz || st != ed) break;
            reread();            
        }
        return true;
    }
    template <class T, enable_if_t<is_integral<T>::value, int> = 0>
    bool read_single(T& ref) {
        if (!succ()) return false;
        bool neg = false;
        if (line[st] == '-') {
            neg = true;
            st++;
        }
        ref = T(0);
        while (isdigit(line[st])) {
            ref = 10 * ref + (line[st++] - '0');
        }
        if (neg) ref = -ref;
        return true;
    }
    template <class T> bool read_single(vector<T>& ref) {
        for (auto& d : ref) {
            if (!read_single(d)) return false;
        }
        return true;
    }
    void read() {}
    template <class H, class... T> void read(H& h, T&... t) {
        bool f = read_single(h);
        assert(f);
        read(t...);
    }
    Scanner(FILE* _fp) : fp(_fp) {}
};

struct Printer {
  public:
    template <bool F = false> void write() {}
    template <bool F = false, class H, class... T>
    void write(const H& h, const T&... t) {
        if (F) write_single(' ');
        write_single(h);
        write<true>(t...);
    }
    template <class... T> void writeln(const T&... t) {
        write(t...);
        write_single('\n');
    }
    void flush() {
        fwrite(line, 1, pos, fp);
        pos = 0;
    }

    Printer(FILE* _fp) : fp(_fp) {}
    ~Printer() { flush(); }

  private:
    static constexpr size_t SIZE = 1 << 15;
    FILE* fp;
    char line[SIZE], small[50];
    size_t pos = 0;
    void write_single(const char& val) {
        if (pos == SIZE) flush();
        line[pos++] = val;
    }
    template <class T, enable_if_t<is_integral<T>::value, int> = 0>
    void write_single(T val) {
        if (pos > (1 << 15) - 50) flush();
        if (val == 0) {
            write_single('0');
            return;
        }
        if (val < 0) {
            write_single('-');
            val = -val;  // todo min
        }
        size_t len = 0;
        while (val) {
            small[len++] = char('0' + (val % 10));
            val /= 10;
        }
        for (size_t i = 0; i < len; i++) {
            line[pos + i] = small[len - 1 - i];
        }
        pos += len;
    }
    void write_single(const string& s) {
        for (char c : s) write_single(c);
    }
    void write_single(const char* s) {
        size_t len = strlen(s);
        for (size_t i = 0; i < len; i++) write_single(s[i]);
    }
    template <class T> void write_single(const vector<T>& val) {
        auto n = val.size();
        for (size_t i = 0; i < n; i++) {
            if (i) write_single(' ');
            write_single(val[i]);
        }
    }
    void write_single(long double d){
        {
            long long v=d;
            write_single(v);
            d-=v;
        }
        write_single('.');
        for(int _=0;_<8;_++){
            d*=10;
            long long v=d;
            write_single(v);
            d-=v;
        }
    }
};

Scanner sc(stdin);
Printer pr(stdout);


int N, M;
vector<int> A, B;

int main() {
  int numCases;
  sc.read(numCases);
  for (; numCases--; ) {
    sc.read(N, M);
    A.resize(M);
    B.resize(M);
    for (int i = 0; i < M; ++i) {
      sc.read(A[i], B[i]);
      --A[i];
      --B[i];
    }
    
    vector<pair<int, int>> dus(N);
    for (int u = 0; u < N; ++u) {
      dus[u] = make_pair(0, u);
    }
    for (int i = 0; i < M; ++i) {
      ++dus[A[i]].first;
      ++dus[B[i]].first;
    }
    sort(dus.begin(), dus.end());
    vector<int> deg(N);
    vector<int> tr(N, -1);
    for (int u = 0; u < N; ++u) {
      deg[u] = dus[u].first;
      tr[dus[u].second] = u;
    }
    for (int i = 0; i < M; ++i) {
      A[i] = tr[A[i]];
      B[i] = tr[B[i]];
    }
// cerr<<"N = "<<N<<", M = "<<M<<endl<<"A = "<<A<<endl<<"B = "<<B<<endl<<"deg = "<<deg<<endl;
    
    vector<vector<int>> graph(N);
    for (int i = 0; i < M; ++i) {
      graph[A[i]].push_back(B[i]);
      graph[B[i]].push_back(A[i]);
    }
    for (int u = 0; u < N; ++u) {
      sort(graph[u].begin(), graph[u].end());
    }
    vector<int> pre(N + 1, N);
    vector<int> degSum(N + 1, 0);
    for (int u = 0; u < N; ++u) {
      pre[u + 1] = min(pre[u], deg[u] ? graph[u][0] : N);
      degSum[u + 1] = degSum[u] + deg[u];
    }
    
    int K = -1;
    for (int k = 0; k <= N; ++k) {
      bool ok = true;
      ok = ok && (k <= pre[k]);
      ok = ok && (M - degSum[k] == 1LL * (N-k) * (N-k - 1) / 2);
      if (ok) {
        K = k;
        break;
      }
    }
// cerr<<"K = "<<K<<endl;
    assert(~K);
    
    int ans[2] = {};
    // ind
    {
      // +1
      for (int u = K; u < N; ++u) if (deg[u] == N-K - 1) {
        ++ans[0];
      }
      // +0
      if (ans[0] == 0) {
        ++ans[0];
        for (int u = K; u < N; ++u) if (deg[u] == N-K) {
          ++ans[0];
        }
      }
    }
    // clique
    {
      // +1
      for (int u = 0; u < K; ++u) if (deg[u] == N-K) {
        ++ans[1];
      }
      // +0
      if (ans[1] == 0) {
        ++ans[1];
        for (int u = 0; u < K; ++u) if (deg[u] == N-K - 1) {
          ++ans[1];
        }
      }
    }
    
    printf("%d %d\n", ans[1], ans[0]);
  }
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 190ms
memory: 10124kb

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