310172: CF1792F1. Graph Coloring (easy version)

Memory Limit:512 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Graph Coloring (easy version)

题意翻译

简单版和困难版之间的唯一区别是 $n$ 的数据范围不同。 给出一个 $n$ 个顶点的无向完全图。完全图是指图上任意两个顶点皆有一条边相连。你需要给图上的每条边染上红色或蓝色。 一个顶点的集合 $S$ 被称作是**红色连接**的,如果对于 $S$ 中每对顶点 $(v_1,v_2)$,都存在只通过红边和 $S$ 中顶点的路径。相仿地,一个顶点的集合 $S$ 被称作是**蓝色连接**的,如果对于 $S$ 中每对顶点 $(v_1,v_2)$,都存在只通过蓝边和 $S$ 中顶点的路径。 你需要以如下方式对图进行染色: - 至少有一条红边。 - 至少有一条蓝边。 - 对于每个大小不小于 $2$ 的顶点集 $S$(也即 $|S|\geqslant 2$),$S$ 或者是红色连接的,或者是蓝色连接的,但不能同时是红色和蓝色连接的。 计算染色方法数对 $998244353$ 取模后的结果。

题目描述

The only difference between the easy and the hard version is the constraint on $ n $ . You are given an undirected complete graph on $ n $ vertices. A complete graph is a graph where each pair of vertices is connected by an edge. You have to paint the edges of the graph into two colors, red and blue (each edge will have one color). A set of vertices $ S $ is red-connected if, for every pair of vertices $ (v_1, v_2) $ such that $ v_1 \in S $ and $ v_2 \in S $ , there exists a path from $ v_1 $ to $ v_2 $ that goes only through red edges and vertices from $ S $ . Similarly, a set of vertices $ S $ is blue-connected if, for every pair of vertices $ (v_1, v_2) $ such that $ v_1 \in S $ and $ v_2 \in S $ , there exists a path from $ v_1 $ to $ v_2 $ that goes only through blue edges and vertices from $ S $ . You have to paint the graph in such a way that: - there is at least one red edge; - there is at least one blue edge; - for each set of vertices $ S $ such that $ |S| \ge 2 $ , $ S $ is either red-connected or blue-connected, but not both. Calculate the number of ways to paint the graph, and print it modulo $ 998244353 $ .

输入输出格式

输入格式


The first (and only) line contains one integer $ n $ ( $ 3 \le n \le 5 \cdot 10^3 $ ).

输出格式


Print one integer — the number of ways to paint the graph, taken modulo $ 998244353 $ .

输入输出样例

输入样例 #1

3

输出样例 #1

6

输入样例 #2

4

输出样例 #2

50

输入样例 #3

100

输出样例 #3

878752271

输入样例 #4

1337

输出样例 #4

520628749

Input

题意翻译

简单版和困难版之间的唯一区别是 $n$ 的数据范围不同。 给出一个 $n$ 个顶点的无向完全图。完全图是指图上任意两个顶点皆有一条边相连。你需要给图上的每条边染上红色或蓝色。 一个顶点的集合 $S$ 被称作是**红色连接**的,如果对于 $S$ 中每对顶点 $(v_1,v_2)$,都存在只通过红边和 $S$ 中顶点的路径。相仿地,一个顶点的集合 $S$ 被称作是**蓝色连接**的,如果对于 $S$ 中每对顶点 $(v_1,v_2)$,都存在只通过蓝边和 $S$ 中顶点的路径。 你需要以如下方式对图进行染色: - 至少有一条红边。 - 至少有一条蓝边。 - 对于每个大小不小于 $2$ 的顶点集 $S$(也即 $|S|\geqslant 2$),$S$ 或者是红色连接的,或者是蓝色连接的,但不能同时是红色和蓝色连接的。 计算染色方法数对 $998244353$ 取模后的结果。

加入题单

算法标签: