[杂题] Codeforces 794D Round #414 D. Labelling Cities
来源:互联网 发布:信息技术网络研修总结 编辑:程序博客网 时间:2024/06/15 22:12
可以证明有相同邻接节点集合的点染色必相同 否则必不相同 缩点
然后一个点度不超过2且连通 然后就是一条链或环 环肯定不可能
然后就好了
#include<cstdio>#include<cstdlib>#include<algorithm>#include<map>#include<set>#include<vector>#define pb push_backusing namespace std;typedef pair<int,int> abcd;typedef unsigned long long ull;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=300005;map<ull,int> idx;int tot;set<abcd> Set;vector<int> G[N];int n,m;int u[N],v[N];ull a[N],b[N];int deg[N];int c[N];inline void dfs(int u,int x){ c[u]=x; for (int v:G[u]) if (!c[v]) dfs(v,x+1);}int main(){ freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(m); for (int i=1;i<=n;i++) a[i]=b[i]=(ull)rand()*rand()*rand()*rand(); for (int i=1;i<=m;i++){ read(u[i]); read(v[i]); a[u[i]]^=b[v[i]]; a[v[i]]^=b[u[i]]; } for (int i=1;i<=n;i++) if (!idx.count(a[i])) idx[a[i]]=++tot; int ed=0; for (int i=1;i<=m;i++){ int x=idx[a[u[i]]],y=idx[a[v[i]]]; if (x>y) swap(x,y); if (x!=y && !Set.count(abcd(x,y))){ Set.insert(abcd(x,y)),ed++; deg[x]++; deg[y]++; G[x].pb(y); G[y].pb(x); } } for (int i=1;i<=tot;i++) if (deg[i]>=3) return printf("NO\n"),0; if (ed==tot) return printf("NO\n",0); for (int i=1;i<=tot;i++) if (deg[i]<=1 && !c[i]) dfs(i,1); printf("YES\n"); for (int i=1;i<=n;i++) printf("%d ",c[idx[a[i]]]); return 0;}
阅读全文
0 0
- [杂题] Codeforces 794D Round #414 D. Labelling Cities
- CodeForces 794D. Labelling Cities
- codeforces 794 D Labelling Cities(脑洞)
- Codeforces Round #257 (Div. 2) D. Jzzhu and Cities
- Codeforces Round #257 div.2 D or 450D Jzzhu and Cities【最短路】
- Codeforces Round #257 (Div. 2) D Jzzhu and Cities 最短路
- Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路
- Codeforces Round#213D
- Codeforces Round#131D
- Codeforces Round 341D
- Codeforces Round #428 D
- Codeforces Round #433 D
- codeforces round #441 D
- Codeforces Testing Round #9 D/386D
- CodeForces Round 230 Div2 D
- codeforces div2 round#230 D
- Codeforces Round #270 A~D
- Codeforces Round #317div2 D
- command not found: shopt linux 配置./bashrc 错误
- java标示符
- 基于stm32的热释传感器模块(库函数编程)
- js插件
- LR与SVM的异同
- [杂题] Codeforces 794D Round #414 D. Labelling Cities
- python 中__name__ = '__main__' 的作用
- M_SYSTEM
- strlen和sizeof的区别
- RabbitMQ在Ubuntu 16.04下的安装教程——官方文档翻译
- NGUI开发优化技巧(上)
- T_CHOUSA
- VC++之绘制线条
- 七牛云图片服务器搭建,对接