日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

poj 3398 (树上的最小支配集)

發布時間:2025/5/22 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 3398 (树上的最小支配集) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?入門題吧。。。

?

Perfect Service
Time Limit:?2000MS?Memory Limit:?65536K
Total Submissions:?1220?Accepted:?593

Description

A network is composed of?N?computers connected by?N?? 1 communication links such that any two computers can be communicated via a unique route. Two computers are said to be?adjacent?if there is a communication link between them. The?neighbors?of a computer is the set of computers which are adjacent to it. In order to quickly access and retrieve large amounts of information, we need to select some computers acting as?servers?to provide resources to their neighbors. Note that a server can serve all its neighbors. A set of servers in the network forms a?perfect service?if every client (non-server) is served byexactly one?server. The problem is to find a minimum number of servers which forms a perfect service, and we call this number?perfect service number.

We assume that?N?(≤ 10000) is a positive integer and these?N?computers are numbered from 1 to?N. For example, Figure 1 illustrates a network comprised of six computers, where black nodes represent servers and white nodes represent clients. In Figure 1(a), servers 3 and 5 do not form a perfect service because client 4 is adjacent to both servers 3 and 5 and thus it is served by two servers which contradicts the assumption. Conversely, servers 3 and 4 form a perfect service as shown in Figure 1(b). This set also has the minimum cardinality. Therefore, the perfect service number of this example equals two.

Your task is to write a program to compute the perfect service number.

Input

The input consists of a number of test cases. The format of each test case is as follows: The first line contains one positive integer,?N, which represents the number of computers in the network. The next?N?? 1 lines contain all of the communication links and one line for each link. Each line is represented by two positive integers separated by a single space. Finally, a 0 at the (N + 1)th line indicates the end of the first test case.

The next test case starts after the previous ending symbol 0. A ?1 indicates the end of the whole inputs.

Output

The output contains one line for each test case. Each line contains a positive integer, which is?
the perfect service number.

Sample Input

6 1 3 2 3 3 4 4 5 4 6 0 2 1 2 -1

Sample Output

2 1

Source

Kaohsiung 2006

?

#include <stdio.h> #include <math.h> #include <string.h> #include <iostream> using namespace std; #define N 20010struct node {int to,next; }edge[2*N];int cnt,pre[N]; int n; int mark[N]; int f[N]; int g[N]; int num;void add_edge(int u,int v) {edge[cnt].to=v;edge[cnt].next=pre[u];pre[u]=cnt++; }void DFS(int s) {mark[s]=1;g[num++]=s;for(int p=pre[s];p!=-1;p=edge[p].next){int v=edge[p].to;if(mark[v]==0){f[v]=s;DFS(v);}} }int greedy() {int set[N];memset(set,0,sizeof(set));memset(mark,0,sizeof(mark));int sum=0;for(int i=num-1;i>=0;i--){int k=g[i];if(mark[k]==0){if(set[f[k]]==0){set[f[k]]=1;sum++;}mark[k]=1;mark[f[k]]=1;mark[f[f[k]]]=1;}}return sum; }int main() {while(scanf("%d",&n)&&(n!=-1)){if(n==0) continue;cnt=0;num=0;memset(pre,-1,sizeof(pre));memset(f,0,sizeof(f));for(int i=1;i<n;i++){int x,y;scanf("%d%d",&x,&y);add_edge(x,y);add_edge(y,x);}f[1]=1;memset(mark,0,sizeof(mark));DFS(1);printf("%d\n",greedy());}return 0; }

?

轉載于:https://www.cnblogs.com/chenhuan001/archive/2013/03/18/2965858.html

總結

以上是生活随笔為你收集整理的poj 3398 (树上的最小支配集)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 免费在线观看高清影视网站 | 西比尔在线观看完整视频高清 | 亚洲一区二区三区蜜桃 | 6—12呦国产精品 | 国产偷拍一区二区三区 | 久久久久久久久久一区二区三区 | www天天干 | www.97色 | 91av国产精品 | 嫩草国产精品 | 久久视频一区二区三区 | 四虎视频国产精品免费入口 | 91视频直接看 | 极品少妇一区二区三区 | 1000部国产精品成人观看 | 亚洲精品三 | 精品人妻无码一区二区 | 番号动态图 | 泽村玲子av| 黄色操人| 日本一本久久 | 午夜影院免费在线观看 | 男人天堂一区 | 欧美日韩一区二区三区在线播放 | 午夜亚洲福利 | 草草视频在线 | 黄色片链接 | 欧美日韩免费视频 | 嫩草在线播放 | 日本人性爱视频 | 韩国一区二区在线播放 | 国产在线观看无码免费视频 | 国产精品大片 | 加勒比波多野结衣 | 久久精品亚洲精品国产欧美 | 中文字幕35页 | 久久久久国产一区二区 | 日本一区二区三区中文字幕 | www.精品一区 | 福利国产视频 | 草女人视频 | 精品免费国产一区二区三区四区 | 熊猫电影yy8y全部免费观看 | 又粗又大又硬毛片免费看 | 欧美激情亚洲激情 | 色七七在线 | 1000部啪啪未满十八勿入 | 国产chinesehd精品露脸 | 久久免费电影 | av不卡在线免费观看 | 中文字幕第一页av | 天天干天天噜 | 美女一区二区三区四区 | 狠狠操婷婷 | www日本高清| 巨胸大乳www视频免费观看 | 国产福利免费观看 | 在线观看日韩av电影 | 亚洲专区一区 | 精品在线小视频 | 久久精品欧美一区二区三区不卡 | 欧美一区二区三区色 | 国产精品久久久久久亚洲影视 | 一区二区久久 | 国产人妻人伦精品1国产 | 欧美色图亚洲视频 | 碰在线视频 | 久色视频在线播放 | 亚洲欧美日韩成人 | 国产成人无码AA精品区 | 日本捏奶吃奶的视频 | 免费黄色小视频 | 91精品国产精品 | 美日韩一区二区三区 | 亚洲在线网站 | 国产精品自拍电影 | 日本草逼视频 | 黄色小视频网 | 美女脱裤子让男人捅 | 婷婷综合色 | 91新网站 | 强开小受嫩苞第一次免费视频 | 美女乱淫| www.欧美一区二区三区 | 日韩精品成人在线 | 欧美性猛交xxxx乱大交蜜桃 | 亚洲AV无码成人精品区明星换面 | 国产精品一区二区三区四区视频 | 久久伊人影视 | 俺去射| 少妇精品一区 | 日本爽爽爽爽爽爽在线观看免 | 污视频免费在线观看网站 | 极品美女开粉嫩精品 | 久久九九热视频 | 亚洲aaaaa特级 | 久久久在线 | 三级黄色在线视频 | 国产资源站|