• Educational Codeforces Round37 E


    #include <algorithm>
    #include <cstdio>
    #include <iostream>
    #include <queue>
    #include <set>
    using namespace std;
    const int N = 2e5 + 5;
    
    vector<int> result;
    std::set<pair<int, int> > unExistedMap;
    int nextPoint[N];
    int prePoint[N];
    class List {
       private:
        int headPoint;
        void initialize(int n) {
            headPoint = 1;
            for (int i = 1; i <= n; ++i) {
                nextPoint[i] = i + 1;
                prePoint[i] = i - 1;
            }
            nextPoint[n] = 0;
            prePoint[1] = 0;
        }
        void deletePoint(int pos) {
            int prePos = prePoint[pos];
            int nexPos = nextPoint[pos];
            nextPoint[prePos] = nexPos;
            prePoint[nexPos] = prePos;
            if (prePos == 0)
                headPoint = nexPos;
        }
    
       public:
        List(int n) { initialize(n); }
        void Solve() {
            while (1) {
                if (headPoint == 0)
                    break;
                std::queue<int> bfsQueue;
                bfsQueue.push(headPoint);
                deletePoint(headPoint);
                int totalMapSeg = 0;
                while (!bfsQueue.empty()) {
                    totalMapSeg++;
                    int nowPoint = bfsQueue.front();
                    bfsQueue.pop();
                    for (int i = headPoint; i; i = nextPoint[i]) {
                        int from = nowPoint;
                        int to = i;
                        if (from > to)
                            swap(from, to);
                        if (unExistedMap.find(std::make_pair(from, to)) == unExistedMap.end()) {
                            bfsQueue.push(i);
                            deletePoint(i);
                        }
                    }
                }
                result.push_back(totalMapSeg);
            }
        }
    };
    
    int main() {
        int n, m;
        while (~scanf("%d %d", &n, &m)) {
            unExistedMap.clear();
            result.clear();
            for (int i = 0; i < m; ++i) {
                int from, to;
                scanf("%d %d", &from, &to);
                if (from > to)
                    swap(from, to);
                unExistedMap.insert(std::make_pair(from, to));
            }
    
            List Basa = List(n);
            Basa.Solve();
    
            sort(result.begin(), result.end());
            printf("%d
    ", (int)result.size());
            for (int i = 0; i < result.size(); ++i) {
                printf("%d ", result[i]);
            }
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    数组按行访问和按列访问的区别
    解决github中图片无法显示问题的策略
    C#验证帮助类(手机号、身份证等)
    WPF圆角按钮样式
    弗洛伊德的本我、自我与超我概念
    KEPServerEX OPCUA服务器地址配置
    C#List的一些操作
    梦、清醒梦、梦魇
    类说明head部格式
    阅读笔记20222
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433807.html
Copyright © 2020-2023  润新知