Classic
Clean & simple
Crystal
Glassmorphism + Neon
Cyberpunk
Neon glitch art
🚫
违规Action检测
禁止Use右键菜单
⚠️ 此Action已被系统记录
1

Dominos 2

📝 Solutions 🔵 仅限 C++
Problems Description
<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>
Input格式
<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>
Output格式
<p>For each test case, output a line containing one integer, the total number of dominos that fall over.</p>
Sample
Sample Input 1
1 3 2 1 1 2 2 3 2
Sample Output 1
2
Submit Code
请先Login后Submit

🤖 AI 解题助手

OpenRouter
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这problems题,可以帮你points析思路、提供Code示例。
🔓 完全Free · 无需消耗 Token