• 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;
    }
    
  • 相关阅读:
    C语言位操作
    Ribbon负载规则的替换
    Nginx 的配置文件
    Nginx 操作常用的命令
    Nginx 是什么?
    SpringCloud Eureka 新版本依赖
    @Autowired 与@Resource的区别
    spring 注释
    redis 的 rdb 和 aof 持久化的区别
    jdk1.7下HashMap的头插法问题
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433807.html
Copyright © 2020-2023  润新知