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

边栏推荐
- R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
- [applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions
- Lex & yacc & bison & flex configuration problems
- The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
- Embrace the safety concept of platform delivery
- 无向图的割点
- R language ggplot2 visual faceting, visual facet_wrap bar plot, using strip Text function customize the size of the strip of each facet title in the facet graph (cutimi
- Leetcode-241: designing priorities for operational expressions
- The difference between tail -f, tail -f and tail
- [case sharing] let the development of education in the new era advance with "number"
猜你喜欢
![[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)](/img/f5/3ec22f1480227f33a1c8ac457155ed.jpg)
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)

Embrace the safety concept of platform delivery

【AutoSAR 九 C/S原理架构】

信息熵的基础

Teach you JDBC hand in hand -- structure separation

Understanding and distinguishing of some noun concepts in adjustment / filtering

Correctly distinguish the similarities and differences among API, rest API, restful API and web service
![[C language] branch and loop statements (Part 1)](/img/47/6efcc59bd26e26f66c698635c26c8b.png)
[C language] branch and loop statements (Part 1)
![[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions](/img/ea/ee1ad50a497478b9d080bb5e4bdfb5.png)
[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions
![[AUTOSAR VI description document]](/img/3d/1382acbc4054ab218485a12b7b4e6b.png)
[AUTOSAR VI description document]
随机推荐
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
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
Delete duplicate elements in the ordered linked list -ii
【AutoSAR 四 BSW概述】
【AutoSAR 一 概述】
[love crash] neglected details of gibaro
[AUTOSAR II appl overview]
excel IF公式判断两列是否相同
电话网络问题
瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
Key detection and sinusoidal signal output developed by Arduino
leetcode-241:为运算表达式设计优先级
KingbaseES ALTER TABLE 中 USING 子句的用法
指针进阶(一)
matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
Several cases of recursive processing organization
[AUTOSAR twelve mode management]
比较版本号
(C语言)数据的存储