码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces - 1228D

时间:2019-09-30 14:30:19      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:code   lag   pair   cto   https   info   图论   air   max   

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

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

传送链接: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\n");
		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\n");
		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\n");
							return 0;
						}
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%d ", dfn[i]);
	}
	printf("\n");
	return 0;
}

  

CodeForces - 1228D

标签:code   lag   pair   cto   https   info   图论   air   max   

原文地址:https://www.cnblogs.com/lesning/p/11612391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!