QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#22809. Comunicaciones por fibra

统计

Farmer John quiere conectar $N$ graneros ($1 \le N \le 1{,}000$), numerados $1..N$, con fibra óptica. Rodean un estanque en círculo, así que solo se pueden conectar vecinos; el granero $N$ es vecino del 1.

No necesita conectar todos: solo ciertas parejas de vacas desean comunicarse. Quiere el mínimo de conexiones que permita todas esas comunicaciones por la red. Dadas las parejas, halla el mínimo de líneas. Para comunicar 1 con 3, deben tenderse 1-2 y 2-3.

Entrada

  • Línea $1$: enteros $N$ y $P$, este último es el número de parejas ($1 \le P \le 10{,}000$).

  • Líneas $2..P+1$: dos enteros que indican una pareja de graneros que desea comunicarse. No hay parejas repetidas.

Salida

Una línea con un entero, el mínimo de conexiones directas necesarias.

Ejemplos

Entrada 1

5 2
1 3
4 5

Salida 1

3

Nota

Conectan las parejas 1-2, 2-3 y 4-5.

Créditos: Reid Barton, 2001.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.