• CodeForces


    乍一看,嗯,图论题,不错;

    结果,这尼玛是模拟????

    传送链接:https://codeforces.com/contest/1228/problem/D

    看了大佬的代码瞬间就明白了许多!!!

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<set>
    #define maxn 300300
    using namespace std;
    int de[maxn];
    vector<int>anc[100];
    
    int n, m;
    int vis[maxn];
    int dfn[maxn];
    int flag = 0;
    set<pair<int, int>>ins;
    int main() {
    	int be, en;
    	scanf("%d %d", &n, &m);
    	if (m == 0) {
    		printf("-1
    ");
    		return 0;
    	}
    	for (int i = 0; i < m; i++) {
    		scanf("%d %d", &be, &en);
    		ins.insert({ be,en });
    		ins.insert({ en,be });
    	}
    	int cnt = 0;
    	for (int i = 1; i <= n; i++) {
    		if (dfn[i]) continue;
    
    		cnt++;
    		for (int j = i; j<=n ; j++) {
    			if (ins.find({ i,j }) == ins.end()) {
    				dfn[j] = cnt;
    				anc[cnt].push_back(j);
    			}
    		}
    	}
    	if (cnt != 3 || anc[1].size() * anc[2].size() + anc[2].size() * anc[3].size() + anc[3].size() *anc[1].size() != m) {
    		printf("-1
    ");
    		return 0;
    	}
    	else {
    		for (int i = 1; i <= 3; i++) {
    			for (int j = i + 1; j <= 3; j++) {
    				for (int k = 0; k < anc[i].size(); k++) {
    					int x = anc[i][k];
    					for (int s = 0; s < anc[j].size(); s++) {
    						int p = anc[j][s];
    						if (ins.find({ x, p }) == ins.end()) {
    							printf("-1
    ");
    							return 0;
    						}
    					}
    				}
    			}
    		}
    	}
    	for (int i = 1; i <= n; i++) {
    		printf("%d ", dfn[i]);
    	}
    	printf("
    ");
    	return 0;
    }
    

      

    寻找真正的热爱
  • 相关阅读:
    三级菜单python写法(递归写法)
    webstorm2018.1.6版本安装+破解+汉化
    sourceTree 的使用教程
    nodeppt的使用教程
    堆和栈的区别(转过无数次的文章)
    黎曼滤波在神经计算方面的应用
    深度学习笔记——PCA原理与数学推倒详解
    TCP/IP模型详解
    OSI7层模型详解
    CNN车型分类总结
  • 原文地址:https://www.cnblogs.com/lesning/p/11612391.html
Copyright © 2020-2023  润新知