当前位置:网站首页>Telephone network problems
Telephone network problems
2022-07-03 01:07:00 【chengqiuming】
One Link to original question
Network - POJ 1144 - Virtual Judge
https://vjudge.net/problem/POJ-1144
Two Input and output
1 Input
The input contains multiple test cases . Each test case describes a network . The... Of each test case 1 Everything is N. Next up N Each row in the row contains a location number , Followed by the number of the place where the place can be reached . Each test case contains only 0 The end of the line .N=0 When the input is over , Don't deal with .
2 Output
For each test case , Output the number of key positions in a single line .
3、 ... and sample input
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Four sample output
1
2
5、 ... and Problem analysis
1 sample input 1, The constructed figure is as follows . In this figure, there are 1 A key point 5.

2 sample input 2, The constructed figure is as follows . There are two key points in this figure , Namely 2 and 5.

This problem is to find the number of cuts , utilize Tarjan The algorithm can be solved .
6、 ... and Code
package graph.poj1144;
import java.util.Scanner;
public class POJ1144 {
static final int maxn = 1000 + 5;
static int n;
static int m;
static int head[];
static int cnt;
static int root;
static int low[];
static int dfn[];
static int cut[];
static int num;
static Edge e[] = new Edge[maxn << 1];
static {
for (int i = 0; i < e.length; i++) {
e[i] = new Edge();
}
}
static void add(int u, int v) { // Add an edge u--v
e[++cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
static void tarjan(int u) { // Please cut point
dfn[u] = low[u] = ++num;
int flag = 0;
for (int i = head[u]; i != 0; i = e[i].next) {
int v = e[i].to;
if (dfn[v] == 0) {
tarjan(v);
low[u] = Math.min(low[u], low[v]);
if (low[v] >= dfn[u]) {
flag++;
if (u != root || flag > 1) {
cut[u] = 1;
}
}
} else
low[u] = Math.min(low[u], dfn[v]);
}
}
static void init() {
head = new int[maxn];
low = new int[maxn];
dfn = new int[maxn];
cut = new int[maxn];
cnt = num = 0;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
n = scanner.nextInt();
if (n == 0)
break;
init();
int u, v;
while (true) {
Scanner scanner1 = new Scanner(System.in);
String nums = scanner1.nextLine();
String[] s = nums.split(" ");
u = Integer.parseInt(s[0]);
if (u == 0) {
break;
}
for (int i = 1; i < s.length; i++) {
v = Integer.parseInt(s[i]);
add(u, v);
add(v, u);
}
}
for (int i = 1; i <= n; i++) {
if (dfn[i] == 0) {
root = i;
tarjan(i);
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (cut[i] == 1)
ans++;
System.out.println(ans);
}
}
}
class Edge {
int to;
int next;
}7、 ... and test result
Green is the input , White is the output

边栏推荐
- FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
- (C语言)数据的存储
- R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
- 用Go+绘制爱心给心爱的她表白
- 12_微信小程序之微信视频号滚动自动播放视频效果实现
- 18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
- matlab 多普勒效应产生振动信号和处理
- leetcode-2280:表示一个折线图的最少线段数
- Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size
- [AUTOSAR twelve mode management]
猜你喜欢

机器学习术语

基于ARM RK3568的红外热成像体温检测系统

Rk3568 development board evaluation (II): development environment construction

Foundations of data science is free to download

FPGA - 7 Series FPGA internal structure clocking -04- multi area clock

研发一款国产ARM智能边缘计算网关需要什么

RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide

12_微信小程序之微信视频号滚动自动播放视频效果实现

Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size

2022.2.14 resumption
随机推荐
[overview of AUTOSAR four BSW]
First hand evaluation of Reza electronics rz/g2l development board
MongoDB系列之MongoDB常用命令
Usage of using clause in kingbases alter table
matlab查找某一行或者某一列在矩阵中的位置
How to systematically learn machine learning
Meaning of Tencent cloud free SSL certificate extension file
研发一款国产ARM智能边缘计算网关需要什么
无向图的割点
Inversion de l'intervalle spécifié dans la liste des liens
数组与集合性能比较
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
leetcode-2280:表示一个折线图的最少线段数
Foundations of data science is free to download
Correctly distinguish the similarities and differences among API, rest API, restful API and web service
Leetcode-849: maximum distance to the nearest person
On Fibonacci sequence
合并K个已排序的链表
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
【AutoSAR 十 IO架构】