1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计点对的数目 [count-pairs-of-nodes].html
2022-03-29 12:43:11 +08:00

43 lines
1.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个无向图,无向图由整数 <code>n</code>  ,表示图中节点的数目,和 <code>edges</code> 组成,其中 <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> 表示 <code>u<sub>i</sub></code> 和 <code>v<sub>i</sub></code><sub> </sub>之间有一条无向边。同时给你一个代表查询的整数数组 <code>queries</code> 。</p>
<p><code>j</code> 个查询的答案是满足如下条件的点对 <code>(a, b)</code> 的数目:</p>
<ul>
<li><code>a < b</code></li>
<li><code>cnt</code> 是与 <code>a</code> <strong>或者 </strong><code>b</code> 相连的边的数目,且 <code>cnt</code> <strong>严格大于 </strong><code>queries[j]</code> 。</li>
</ul>
<p>请你返回一个数组 <code>answers</code> ,其中 <code>answers.length == queries.length</code> 且 <code>answers[j]</code> 是第 <code>j</code> 个查询的答案。</p>
<p>请注意,图中可能会有 <strong>重复边</strong> 。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://pic.leetcode-cn.com/1614828447-GMnLVg-image.png" style="width: 310px; height: 278px;" />
<pre>
<b>输入:</b>n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]
<b>输出:</b>[6,5]
<b>解释:</b>每个点对中,与至少一个点相连的边的数目如上图所示。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]
<b>输出:</b>[10,10,9,8,6]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 <= n <= 2 * 10<sup>4</sup></code></li>
<li><code>1 <= edges.length <= 10<sup>5</sup></code></li>
<li><code>1 <= u<sub>i</sub>, v<sub>i</sub> <= n</code></li>
<li><code>u<sub>i </sub>!= v<sub>i</sub></code></li>
<li><code>1 <= queries.length <= 20</code></li>
<li><code>0 <= queries[j] < edges.length</code></li>
</ul>