当前位置:网站首页>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

边栏推荐
- Sentry developer contribution Guide - configure pycharm
- 瑞萨电子RZ/G2L开发板上手评测
- (C语言)数据的存储
- 详解RDD基本概念、RDD五大属性
- [overview of AUTOSAR four BSW]
- leetcode-1964:找出到每个位置为止最长的有效障碍赛跑路线
- Compare version number
- 2022.2.14 resumption
- leetcode-241:为运算表达式设计优先级
- 2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
猜你喜欢
![[overview of AUTOSAR four BSW]](/img/19/c2273bbedb7f8d859e5a3805ed5740.png)
[overview of AUTOSAR four BSW]

How to systematically learn machine learning

Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem

无向图的割点

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

1.11 - bus

leetcode:701. 二叉搜索树中的插入操作【bst的插入】

Win10 can't be installed in many ways Problems with NET3.5
![[AUTOSAR II appl overview]](/img/da/76ccc05e2199705b20d8304bfb86b2.png)
[AUTOSAR II appl overview]

【AutoSAR 一 概述】
随机推荐
1.12 - Instructions
[C language] branch and loop statements (Part 1)
Several cases of recursive processing organization
mysql 多表联合删除
深度剖析数据在内存中的存储
Embrace the safety concept of platform delivery
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
【AutoSAR 九 C/S原理架构】
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
Asynchronous, email and scheduled tasks
(C language) data storage
In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
Compare version number
[AUTOSAR I overview]
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
leetcode-2115:从给定原材料中找到所有可以做出的菜
leetcode-1964:找出到每个位置为止最长的有效障碍赛跑路线
Test shift right: Elk practice of online quality monitoring
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测