QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#218425#7107. Chaleurucup-team992AC ✓471ms21044kbC++174.0kb2023-10-18 11:26:192023-10-18 11:26:20

Judging History

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

  • [2023-10-18 11:26:20]
  • 评测
  • 测评结果:AC
  • 用时:471ms
  • 内存:21044kb
  • [2023-10-18 11:26:19]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;

seed_seq seq{
    (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
    (uint64_t) __builtin_ia32_rdtsc(),
    (uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq);
// mt19937_64 lrng(seq);

struct debugger{
    template <typename T>
    debugger& operator<<(T &a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
    template <typename T>
    debugger& operator<<(T &&a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
} deb;

const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

//! function insert

//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan

int deg[100001];
void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for(int i{}; i < n; ++i)
        deg[i] = 0;
    for(int i{}; i < m; ++i){
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    set<ar<int, 2>> left;
    set<ar<int, 2>> startdeg;
    for(int i{}; i < n; ++i){
        left.insert({deg[i], i});
        startdeg.insert({deg[i], i});
    }

    vector<bool> inside(n, true);
    while(left.size() && !((*left.rbegin())[0] == (*left.begin())[0] && (*left.begin())[0]+1 == left.size())){
        auto it = *startdeg.begin();
        inside[it[1]] = false;
        startdeg.erase(startdeg.begin());
        left.erase(left.find({deg[it[1]], it[1]}));
        for(int j : adj[it[1]]){
            if(inside[j]){
                left.erase(left.find({deg[j], j}));
                deg[j]--;
                left.insert({deg[j], j});
            }
        }
    }

    int cc{1};
    if(left.size() <= 1){
        cc = max(1ll, m == 0 ? n : m);
    }else{
        for(int i{}; i < n; ++i){
            if(!inside[i]){
                if(adj[i].size() == left.size()-1){
                    cc++;
                }
            }
        }
    }

    int zeros{}, ones{};
    for(auto t : left){
        if(adj[t[1]].size() - deg[t[1]] == 0)
            zeros++;
        else if(adj[t[1]].size() - deg[t[1]] == 1)
            ones++;
    }
    if(left.size() == n)
        zeros = n;
    if(zeros > 0){
        cout << cc << ' ' << zeros << '\n';
    }else if(ones > 0){
        cout << cc << ' ' << ones+1 << '\n';
    }else{
        cout << cc << ' ' << 1 << '\n';
    }
}

uci main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

/*
    random number generator stuff
    num = rng(); gives integer number
    num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
    num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
    can also instantiate distributions and call on generator:
    uniform_int_distribution<int> thing(a, b);
    num = thing(rng);
*/
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = lrng();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 471ms
memory: 21044kb

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