• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

noip76

开发技术 开发技术 4小时前 2次浏览
#include <bits/stdc++.h>
using namespace std;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=y;++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=y;--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<y;++i)
#define mem(a,x,n) memset(a,x,sizeof(a[0])*(n+1))
#define pb emplace_back
#define MP make_pair
#define fi first
#define se second
#define MT make_tuple
#define all(a) a.begin(),a.end()
typedef long long LL; typedef unsigned long long ULL; typedef long double LD;
typedef pair<int,int> PII; typedef vector<int> VI;
char buf[1<<20],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
template<typename T>void read(T &x){
	x=0;bool f=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=0;
	if(f)for(;isdigit(c);c=getchar())x=x*10+c-48;
	else for(;isdigit(c);c=getchar())x=x*10-c+48;
}
template<typename T,typename ...Args>void read(T &x, Args &...args)
	{ read(x),read(args...); }
template<typename T>void write(T x,char y=10) {
	if(!x)putchar(48);
	else{static int s[21];int l=0;if(x<0)putchar('-'),x=-x;
		for(;x;x/=10)s[l++]=x%10;while(l)putchar(s[--l]|48);}
	putchar(y);
}
template<typename T>void ckmax(T &x,T y) { if( y > x ) x = y; }
template<typename T>void ckmin(T &x,T y) { if( y < x ) x = y; }

const int N = 1e3+5, L = 1e9, B = sqrt(L);
int n,m;
bitset<N> w[N];

int s,t,cir,deg[N],ty[N],f[N];
VI a,b;

namespace checker {
void main() {
	if( cir ) cerr<<"cir"<<endl;
	else cerr<<"none"<<endl;
	For(i,1,n) assert(-1e9<=f[i]), assert(f[i]<=1e9);
	For(i,1,n) For(j,i+1,n) {
		assert(f[i]!=f[j]), assert(abs(f[i]-f[j])<=L);
		if( w[i][j] ) assert(abs(f[i]-f[j])>=L/2);
		else assert(abs(f[i]-f[j])<L/2);
	}
}
}

bool cmp(const int &x,const int &y) { return deg[x] > deg[y]; }

bool MAIN() {
	read(n,m);
	For(i,1,m, x,y) read(x,y), w[x][y] = w[y][x] = 1, ++deg[x], ++deg[y];
	s = max_element(deg+1,deg+n+1)-deg;
	For(i,1,n) if( w[s][i] && deg[i] > deg[t] ) t = i;
	if( (w[s]&w[t]).count() > 1 ) return 0;
	if( (w[s]&w[t]).count() ) {
		For(i,1,n) if( w[s][i] && w[t][i] ) cir = i;
		if( deg[cir] != 2 ) return 0;
	}
	For(i,1,n)
		if( i == cir ) ty[i] = -1;
		else if( w[s][i] && w[t][i] ) return 0;
		else if( w[s][i] ) ty[i] = 0, b.pb(i);
		else ty[i] = 1, a.pb(i);
	For(i,1,n) For(j,i+1,n) if( w[i][j] && ty[i] == ty[j] ) return 0;
	stable_sort(all(a),c++mp), stable_sort(all(b),cmp); // s==a[0],t==b[0]
	Rep(i,0,a.size()-1) if( (w[a[i]]&w[a[i+1]]) != w[a[i+1]] ) return 0;
	Rep(i,0,b.size()-1) if( (w[b[i]]&w[b[i+1]]) != w[b[i+1]] ) return 0;
	Rep(i,0,a.size()) f[a[i]] = i * B;
	if( cir ) f[cir] = L/2, f[t] = L;
	else rFor(i,(int)a.size()-1,0) if( w[t][a[i]] )
			{ f[t] = f[a[i]]+L/2+B-1; break; }
	Rep(i,1,b.size(), j = (int)a.size()-1) {
		f[b[i]] = f[b[i-1]]-1;
		while( j && !w[b[i]][a[j]] ) --j;
		while( f[b[i]]-f[a[j]]-B >= L/2 ) f[b[i]] -= B;
	}
	puts("Yes"), write(L,' ');
	For(i,1,n) write(f[i],i<n?' ':'n');
//	checker::main();
	return 1;
} signed main() {
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	int T; read(T); while( T-- ) {
		s = t = cir = 0;
		mem(deg,0,n);
		For(i,1,n) w[i].reset();
		a.clear(), b.clear();
		if( !MAIN() ) puts("No");
	}
	return 0;
}

程序员灯塔
转载请注明原文链接:noip76
喜欢 (0)