当前位置: 代码迷 >> 综合 >> codeforce 623 A
  详细解决方案

codeforce 623 A

热度:40   发布时间:2024-01-11 16:09:18.0



因为只有a b c , b 和其他都联通, 从这里突破


#include <bits/stdc++.h>
using namespace std ;typedef long long ll ;
const int inf = 0x3f3f3f3f ;
const int maxn = 550 ;
bool g[maxn][maxn] ;
int deg[maxn] ;
bool vis[maxn] ;
char ans[maxn] ;
bool check(char a , char b){int x = a - 'a' , y = b - 'a' ;if( fabs(x - y) <= 1 ) return true ;return false ;
}
bool CHECK(int n){for(int i = 1 ; i <= n ; i ++ ){for(int j = i + 1 ; j <= n ; j ++ ){if((check(ans[i] , ans[j]) && g[i][j] == 1) || (!check(ans[i] , ans[j]) && !g[i][j]))continue ;else{return false ;}}}return true ;
}
int main(){int n , m , a , b;scanf("%d %d" , &n , &m) ;memset(g , 0 , sizeof(g)) ;memset(deg , 0 , sizeof(deg)) ;memset(vis , 0 , sizeof(vis)) ;for(int i = 0 ; i < m ; i ++ ){scanf("%d %d" , &a , &b) ;deg[a] ++ , deg[b] ++ ;g[a][b] = g[b][a] = 1 ;}for(int i = 1 ; i <= n ; i ++ ){if(deg[i] == n - 1){vis[i] = 1 ;ans[i] = 'b' ;}}for(int i = 1 ; i <= n ; i ++ ){if(!vis[i]){vis[i] = 1 ;ans[i] = 'a' ;for(int j = 1 ; j <= n ; j ++ ){if(vis[j] || g[i][j] == 0) continue ;vis[j] = 1 ;ans[j] = 'a' ;}break ;}}for(int i = 1 ; i <= n ; i ++ ){if(!vis[i]) ans[i] = 'c' ;}//puts(ans + 1) ;//if(m == 95) for(int i = 1 ; i <= n ; i ++ ) printf("%c" , ans[i]) ;if(CHECK(n)) { puts("Yes") ; puts(ans + 1) ; }else puts("No") ;return 0 ;
}