随笔分类 - 图论
摘要:DescriptionGive a tree with n vertices,each edge has a length(positive integer less than 1001).Define dist(u,v)=The min distance between node u and v.Give an integer k,for every pair (u,v) of vertices is called valid if and only if dist(u,v) not exceed k.Write a program that will count how many pair
阅读全文
摘要:DescriptionConsider a tree T with N (1 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int MAXN = 20010; 8 const int MAXE = 40010; 9 const int INF = 0x7fff7fff;10 11 int head[MAXN], size[MAXN], maxSize[MAXN], f[MAXN];12 int to[MAXE], next[MAXE];13 int n, ecnt;14 15 void init()...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2631DescriptionBuilding and maintaining roads among communities in the far North is an expensive business. With this in...
阅读全文
摘要:One day Greg and his friends were walking in the forest. Overall there werenpeople walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that th
阅读全文
摘要:Berland hasncities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not.The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every day Valera chooses exactly one city and orders the crew to a
阅读全文
摘要:DescriptionP. T. Tigris is a student currently studying graph theory. One day, when he was studying hard, GS appeared around the corner shyly and came...
阅读全文
摘要:The traffic network in a country consists of N cities (labeled with integers from 1 to N) and N-1 roads connectingthe cities. There is a unique path between each pair of different cities, and we know the exact length of each road.Write a program that will, for each of the K given pairs of cities, fi
阅读全文
摘要:Description在一些一对一游戏的比赛(如下棋、乒乓球和羽毛球的单打)中,我们经常会遇到A胜过B,B胜过C而C又胜过A的有趣情况,不妨形象的称之为剪刀石头布情况。有的时候,无聊的人们会津津乐道于统计有多少这样的剪刀石头布情况发生,即有多少对无序三元组(A, B, C),满足其中的一个人在比赛中...
阅读全文
摘要:DescriptionWhen FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 const int MAXV = 1010; 9 const int MAXE = 40010;10 const int INF = 0x7f7f7f7f;11 12 struct SPFA_COST_FLOW {13 boo...
阅读全文
摘要:DescriptionDearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area there are N shopkeepers (marked from 1 to N) which stocks goods from him.Dearboy has M supply places (marked from 1 to M), each provides K different kinds of goods (marked from 1 to K). Once s
阅读全文
摘要:DescriptionYoung naturalist Bill studies ants in school. His ants feed on plant-louses that live on apple trees. Each ant colony needs its own apple tree to feed itself.Bill has a map with coordinates ofnant colonies andnapple trees. He knows that ants travel from their colony to their feeding place
阅读全文
摘要:DescriptionAt the end of the 200013thyear of the Galaxy era, the war between Carbon-based lives and Silicon civilization finally comes to its end with the Civil Union born from the ruins. The shadow fades away, and the new-born Union is opening a new page.Although the war ended, the affect of the wa
阅读全文
摘要:DescriptionThis is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algori...
阅读全文
摘要:Description“Farm Game” is one of the most popular games in online community. In the community each player has a virtual farm. The farmer can decide to plant some kinds of crops like wheat or paddy, and buy the corresponding crop seeds. After they grow up, The farmer can harvest the crops and sell th
阅读全文
摘要:DescriptionA Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a t
阅读全文
摘要:DescriptionIn order to get from one of the F (1 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 const int MAXN = 5010; 9 const int MAXE = 20010;10 11 int head[MAXN], sccno[MAXN];12 int to[MAXE], next[MAXE];13 bool vis[MAXE];14 int pre[MAXN], lowlink[MAXN];15 int stk[MAXN...
阅读全文
摘要:DescriptionMirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come to the farm one after another. Each of them has keys to some pig-houses and wants to buy a certain number of pigs. All data concernin
阅读全文
摘要:DescriptionEvery cow's dream is to become the most popular cow in the herd. In a herd of N (1 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int MAXN = 10010; 8 const int MAXE = 50010; 9 10 int outdeg[MAXN], pre[MAXN], lowlink[MAXN], sum[MAXN];11 int head[MAXN], sccno[MAXN], .
阅读全文
摘要:DescriptionBob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree. He has to put the minimum number of soldiers on t
阅读全文
摘要:DescriptionKolya has returned from a summer camp and now he's a realcommunication fiend. He spends all his free time on the Web chatting with his friends via ICQ. However, lately the protocol of this service was changed once again, and Kolya's client stopped working. Now, in order to communi
阅读全文