经典简约
清爽简洁,回归本真
液态水晶
毛玻璃+霓虹光带
赛博朋克
霓虹故障艺术风
🚫
违规操作检测
禁止使用右键菜单
⚠️ 此操作已被系统记录
1

Dominos 2

📝 题解 🔵 仅限 C++
题目描述
<p>Dominos are lots of fun. Children like to stand the tiles on their side in long lines. When one domino falls, it knocks down the next one, which knocks down the one after that, all the way down the line. However, sometimes a domino fails to knock the next one down. In that case, we have to knock it down by hand to get the dominos falling again.</p> <p>Given a set of dominos that are knocked down by hand, your task is to determine the total number of dominos that fall.</p>
输入格式
<p>The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing three integers <i>n, m, l</i> no larger than 10 000, followed by <i>m</i>+<i>l</i> additional lines. The first integer <i>n</i> is the number of domino tiles. The domino tiles are numbered from 1 to <i>n</i>. Each of the <i>m</i> lines after the first line contains two integers <i>x</i> and <i>y</i> indicating that if domino number <i>x</i> falls, it will cause domino number <i>y</i> to fall as well. Each of the following <i>l</i> lines contains a single integer <i>z</i> indicating that the domino numbered <i>z</i> is knocked over by hand.</p>
输出格式
<p>For each test case, output a line containing one integer, the total number of dominos that fall over.</p>
样例
样例输入 1
1 3 2 1 1 2 2 3 2
样例输出 1
2
提交代码
请先登录后提交

🤖 AI 解题助手

DeepSeek
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这道题,可以帮你分析思路、提供代码示例。
⚠️ 请先登录后使用