cf623a

来源:互联网 发布:金和网络摄像头 编辑:程序博客网 时间:2024/06/06 01:05

这个题是比较复杂的了,主要是我一开始想如何判断他不能成,主要是因为这个我一开始想成组合数的了,诶,我一开始就该想明白不应该是组合数的,因为要输出方案,不可能是组合数,这个题主要是用a,c来判,是b的话一定是可以的,先构造一些,然后再用b来判断,最后看如果冲突的话就是no。

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){    int n,m;    while(cin>>n>>m)    {        int str[550][550],cnt[550],ans[550];        memset(str,0,sizeof(str));        memset(cnt,0,sizeof(cnt));        memset(ans,0,sizeof(ans));        for(int i = 0; i < m; i++)        {            int u,v;            cin>>u>>v;            str[u][v] = str[v][u] = 1;            cnt[u]++;            cnt[v]++;        }        for(int i = 1; i <= n; i++)            if(cnt[i] == n - 1)                ans[i] = 1;        for(int i = 1; i <= n; i++)            if(ans[i] == 0)                for(int j = i + 1; j <= n; j++)                    if(str[i][j] == 0)                        ans[j] = 2;        bool flag = true;        for(int i = 1; i <= n; i++)        {            for(int j = i + 1; j <= n; j++)            {                if((abs(ans[i] - ans[j]) == 2 && str[i][j]) || (abs(ans[i] - ans[j]) < 2 && !str[i][j]))                {                    cout<<"No"<<endl;                    flag = false;                    break;                }            }            if(!flag)                break;        }        if(!flag)            continue;        cout<<"Yes"<<endl;        for(int i = 1; i <= n; i++)            printf("%c",ans[i] + 'a');        cout<<endl;    }    return 0;}

晚上和我哥哥吃饭,。,。,。上午扎成筛子,下午练车。和locus玩的倒是挺好。,明天还要手术。。。我身上毛病可真多。但愿有一天我能配上所有人。,,通选易经老师说我桃花旺哈~

0 0
原创粉丝点击