Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
D - Swap Hats
Problem Statement
There are 3 Takahashis wearing hats colored $S_1$, $S_2$, and $S_3$ respectively.
We want to perform exactly $10^{18}$ swap operations to make $S_i = T_i$.
Each operation is defined as:
- Select a pair $(i,j)$ and swap $S_i$ and $S_j$.
Determine if the goal can be achieved.
Input Format
$S_1~S_2~S_3$
$T_1~T_2~T_3$
Output Format
Print Yes
if possible; otherwise, print No
.
Sample
Sample Input
|
|
Sample Output
|
|
Analysis
We manually enumerate all cases. The solution outputs Yes
when all $S_i=T_i$ or all $S_i\ne T_i$ (requiring even parity after $10^{18}$ swaps), otherwise No
.
Code
|
|
E - King Bombee
Problem Statement
Given a simple undirected graph with $N$ vertices and $M$ edges. The $i$-th edge connects vertices $U_i$ and $V_i$.
Count the number of paths from $S$ to $T$ with length $K$ that pass through vertex $X$ an even number of times, modulo $998244353$.
Constraints:
$2\le N\le 2000$
$1\le M\le 2000$
$1\le K\le 2000$
$1\le S,T,X\le N$
$X\ne S,X\ne T$
$1\le U_i < V_i\le N$
All edges are distinct.
Input Format
$N~M~K~S~T~X$
$U_1~V_1$
$\vdots$
$U_M~V_M$
Output Format
Print the count modulo $998244353$.
Sample
Sample Input 1
|
|
Sample Output 1
|
|
Valid paths:
- $1\to2\to1\to2\to3$
- $1\to2\to3\to2\to3$
- $1\to4\to1\to4\to3$
- $1\to4\to3\to4\to3$
Each path visits $X=2$ even times.
Sample Input 2
|
|
Sample Output 2
|
|
Disconnected graph.
Sample Input 3
|
|
Sample Output 3
|
|
Result modulo $998244353$.
Analysis
Define $\mathrm{dp}(i,j,k)$ as the number of paths reaching vertex $j$ in $i$ steps with $k$ being the parity (even/odd) of visits to $X$. Transitions occur via adjacency list:
- When moving to vertex $v$, if $v=X$, toggle the parity bit.
- Use rolling array optimization for space efficiency.
Code
|
|
F - Shortest Good Path
Analysis
Let $\mathrm{dis}[S][j]$ be the shortest length of a good path with respect to bitmask $S$ ending at vertex $j$. Perform BFS where each state $(S, v)$ represents the current bitmask and position. Use bitmask compression for efficiency.
Code
|
|