AIM Tech Round [div2] C. Graph and String

本文探讨了一个有趣的图论问题:如何根据给定的图结构逆向寻找可能的原始字符串,该字符串由字符'a'、'b'和'c'组成,并遵循特定的边连接规则。

C. Graph and String

One day student Vasya was sitting on a lecture and mentioned a string s1s2… sn, consisting of letters “a”, “b” and “c” that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:

G has exactly n vertices, numbered from 1 to n.
For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not. 

Vasya painted the resulting graph near the string and then erased the string. Next day Vasya’s friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya’s adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.

Input

The first line of the input contains two integers n and m — the number of vertices and edges in the graph found by Petya, respectively.

Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.

Output

In the first line print “Yes” (without the quotes), if the string s Petya is interested in really exists and “No” (without the quotes) otherwise.

If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters “a”, “b” and “c” only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.

Sample test(s)

Input

2 1
1 2

Output

Yes
aa

Input

4 3
1 2
1 3
1 4

Output

No

Note

In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings “aa”, “ab”, “ba”, “bb”, “bc”, “cb”, “cc” meets the graph’s conditions.

In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.

思路

考察点与其他点的连接情况,若和其他所有点相连则为b,否则为a,并且未与其相连的为c。并且检查已经确定的点与当前的点的连接情况是否正确。遍历一遍所有点的连接情况即可

代码

#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int a[505][505];
char ans[505];
int main()
{
    int n,m,x,y,ok=1;
    scanf("%d %d",&n,&m);
    while (m--)
    {
        scanf("%d %d",&x,&y);
        a[x][y]=1;
        a[y][x]=1;
    }
    for (int i=1;i<=n;i++)
    {
        int flag=0;
        for (int j=1;j<=n;j++)
        {
            if (i!=j && a[i][j]==0) flag=1;
        }
        if (flag==0) ans[i]='b';
        else 
        {
            if (ans[i]==0) ans[i]='a';
        }
        for (int j=1;j<=n;j++)
        {
            if (i!=j)
            {
                if (flag)
                {
                    if (ans[j]==0)
                    {
                        if (!a[i][j]) ans[j]='a'+'c'-ans[i];
                    }
                    else
                    {
                        if (a[i][j] && ans[j]!='b' && ans[j]!=ans[i]) ok=0;
                        if (!a[i][j] && (ans[j]=='b' || ans[j]==ans[i])) ok=0;
                    }
                }
            }
        } 
    }
    if (ok) printf("Yes\n%s",ans+1);
    else printf("No");
}
内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
关于 Codeforces Round 1014 Div. 2 的具体题解和比赛详情并未在当前提供的引用中提及。然而,可以基于类似的竞赛结构以及常见的算法问题类型提供一些推测性的分析。 通常情况下,Codeforces 比赛中的题目会涉及多种经典算法领域,例如动态规划、贪心策略、图论、字符串处理等。以下是可能适用于该轮次的一些常见问题类型的解答框架: ### 动态规划 (Dynamic Programming) 如果某道题目涉及到最优子结构性质,则可以通过构建状态转移方程来解决问题。例如,在某些背包类问题中,定义 `dp[i][j]` 表示前 i 件物品容量为 j 时的最大价值[^3]。 ```python def knapsack(values, weights, capacity): n = len(values) dp = [[0]*(capacity+1) for _ in range(n+1)] for i in range(1,n+1): for w in range(capacity+1): if weights[i-1] <= w: dp[i][w] = max(dp[i-1][w], values[i-1]+dp[i-1][w-weights[i-1]]) else: dp[i][w] = dp[i-1][w] return dp[n][capacity] values = [60, 100, 120] weights = [10, 20, 30] capacity = 50 print(knapsack(values, weights, capacity)) ``` ### 贪心算法 (Greedy Algorithm) 当面对资源分配等问题时,采用局部最优策略往往能够达到全局最佳效果。比如安排会议时间表以最大化会议室利用率的情形下,按照结束时间排序并依次选取不冲突的区间即可实现目标[^4]。 ### 图论 (Graph Theory) 对于连通性和最短路徑计算方面的需求,Dijkstra 和 Floyd-Warshall 是两种非常实用的方法。前者适合单源最短路径查询;后者则能解决多源场景下的需求[^5]。 ```python import heapq def dijkstra(graph, start_node): distances = {node: float('inf') for node in graph} distances[start_node] = 0 priority_queue = [(0,start_node)] while priority_queue: current_distance, current_vertex = heapq.heappop(priority_queue) if current_distance > distances[current_vertex]: continue for neighbor, weight in graph[current_vertex].items(): distance = current_distance + weight if distance < distances[neighbor]: distances[neighbor] = distance heapq.heappush(priority_queue,(distance,neighbor)) graph = { 'A': {'B': 1,'C': 4}, 'B': {'A': 1,'C': 2,'D': 6}, 'C': {'A': 4,'B': 2,'D': 3}, 'D': {'B': 6,'C': 3} } dijkstra(graph, 'A') ``` 尽管上述内容并非直接针对 Codeforces Round 1014 Div. 2 提供的具体解决方案,但它涵盖了比赛中可能出现的核心知识点和技术手段。 ####
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值