锘??xml version="1.0" encoding="utf-8" standalone="yes"?>777午夜精品久久av蜜臀,久久综合综合久久狠狠狠97色88,久久99国产一区二区三区http://www.shnenglu.com/lvlawliet/category/17929.htmlVIMzh-cnSat, 15 Oct 2011 18:25:38 GMTSat, 15 Oct 2011 18:25:38 GMT60HDU4009:Transfer waterhttp://www.shnenglu.com/lvlawliet/articles/158401.htmlLLawlietLLawlietSat, 15 Oct 2011 14:20:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158401.htmlhttp://www.shnenglu.com/lvlawliet/comments/158401.htmlhttp://www.shnenglu.com/lvlawliet/articles/158401.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158401.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158401.html

Transfer water

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1770    Accepted Submission(s): 650


Problem Description
XiaoA lives in a village. Last year flood rained the village. So they decide to move the whole village to the mountain nearby this year. There is no spring in the mountain, so each household could only dig a well or build a water line from other household. If the household decide to dig a well, the money for the well is the height of their house multiplies X dollar per meter. If the household decide to build a water line from other household, and if the height of which supply water is not lower than the one which get water, the money of one water line is the Manhattan distance of the two households multiplies Y dollar per meter. Or if the height of which supply water is lower than the one which get water, a water pump is needed except the water line. Z dollar should be paid for one water pump. In addition,therelation of the households must be considered. Some households may do not allow some other households build a water line from there house. Now given the 3‐dimensional position (a, b, c) of every household the c of which means height, can you calculate the minimal money the whole village need so that every household has water, or tell the leader if it can’t be done.
 

Input
Multiple cases. 
First line of each case contains 4 integers n (1<=n<=1000), the number of the households, X (1<=X<=1000), Y (1<=Y<=1000), Z (1<=Z<=1000). 
Each of the next n lines contains 3 integers a, b, c means the position of the i‐th households, none of them will exceeded 1000. 
Then next n lines describe the relation between the households. The n+i+1‐th line describes the relation of the i‐th household. The line will begin with an integer k, and the next k integers are the household numbers that can build a water line from the i‐th household. 
If n=X=Y=Z=0, the input ends, and no output for that. 
 

Output
One integer in one line for each case, the minimal money the whole village need so that every household has water. If the plan does not exist, print “poor XiaoA” in one line. 
 

Sample Input
2 10 20 30 1 3 2 2 4 1 1 2 2 1 2 0 0 0 0
 

Sample Output
30
Hint
In 3‐dimensional space Manhattan distance of point A (x1, y1, z1) and B(x2, y2, z2) is |x2‐x1|+|y2‐y1|+|z2‐z1|.
 

Source
 

Recommend
lcy
 

浠婂勾澶ц繛璧涘尯緗戠粶璧涗竴閬撻.....鎴戞庝箞涓鐐瑰嵃璞′篃娌℃湁鍛?....
涓閬撹丹瑁哥殑鏈灝忔爲褰㈠浘錛岄櫎浜嗘暟鎹湁鐐瑰ぇ鑰屽凡.....
鎬濊礬錛氬洜涓烘病鏈夋牴錛屾墍浠ヨ櫄鎷熶竴涓牴錛屾墍鏈夌偣鍜岃繖涓牴榪炵嚎錛屾潈鍊兼槸璇ョ偣閫犱簳鐨勪環(huán)鏍鹼紝榪欐牱浠ヨ繖涓牴鍑哄彂錛屾瀯閫犲嚭鏉ョ殑鏈灝忔爲褰㈠浘灝辨槸鏈灝忕殑璐圭敤浜嗐?br />浠g爜錛?br />
#include <cstdio>
#include 
<cstring>
#include 
<cmath>
#include 
<iostream>
using namespace std;

const int maxn = 1100;
const int maxm = 1100000;
const int maxint = 0x3fffffff;

struct edge
{
    
int u, v, w;
    edge(){}
    edge(
int u1, int v1, int w1) : u(u1), v(v1), w(w1){}
} e[maxm];

int root, n, edgeNum, vis[maxn], pre[maxn], belong[maxn], in[maxn];
int a[maxn], b[maxn], c[maxn];
int Abs(int a)
{
    
return a > 0 ? a : -a;
}

int Dis(int i, int j)
{
    
return Abs(a[i] - a[j]) + Abs(b[i] - b[j]) + Abs(c[i] - c[j]);
}

int solve()
{
    
int i, j, k, num, sum = 0;
    n
++;
    
while (1)
    {
        
for (i = 0; i < n; ++i)
            
in[i] = maxint;
        
for (i = 0; i < edgeNum; ++i)
        {
            
if (in[e[i].v] > e[i].w && e[i].u != e[i].v)
            {
                pre[e[i].v] 
= e[i].u;
                
in[e[i].v] = e[i].w;
            }
        }

        memset(vis, 
-1sizeof(vis));
        memset(belong, 
-1sizeof(belong));
        
in[root] = 0;
        
for (num = 0, i = 0; i < n; ++i)
        {
            sum 
+= in[i];
            j 
= i;
            
while (vis[j] != i && belong[j] == -1 && j != root)
            {
                vis[j] 
= i;
                j 
= pre[j];
            }
            
if (vis[j] == i)
            {
                
for (k = pre[j]; k != j; k = pre[k])
                    belong[k] 
= num;
                belong[j] 
= num++;
            }
        }

        
if (!num) return sum;
        
for (i = 0; i < n; ++i)
            
if (belong[i] == -1)
                belong[i] 
= num++;

        
for (i = 0; i < edgeNum; ++i)
        {
            
int j = e[i].v;
            e[i].u 
= belong[e[i].u];
            e[i].v 
= belong[e[i].v];
            e[i].w 
-= in[j];
        }
        n 
= num;
        root 
= belong[root];
    }
    
return sum;
}

int main()
{
    
int x, y, z, i, j, k, ii, d;
    
while (scanf("%d%d%d%d"&n, &x, &y, &z) != EOF)
    {
        
if (!&& !&& !&& !z) break;
        
for (edgeNum = 0, i = 1; i <= n; ++i)
        {
            scanf(
"%d%d%d"&a[i], &b[i], &c[i]);
            e[edgeNum
++= edge(0, i, c[i] * x);
        }
        
for (i = 1; i <= n; ++i)
        {
            scanf(
"%d"&k);
            
while (k--)
            {
                scanf(
"%d"&ii);
                
if (i == ii) continue;
                d 
= Dis(i, ii);
                
if (c[i] >= c[ii])
                    e[edgeNum
++= edge(i, ii, d * y);
                
else
                    e[edgeNum
++= edge(i, ii, d * y + z);
            }
        }

        root 
= 0;
        printf(
"%d\n", solve());
    }
    
return 0;
}


LLawliet 2011-10-15 22:20 鍙戣〃璇勮
]]>
HDU2121:Ice_cream鈥檚 world IIhttp://www.shnenglu.com/lvlawliet/articles/158400.htmlLLawlietLLawlietSat, 15 Oct 2011 14:18:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158400.htmlhttp://www.shnenglu.com/lvlawliet/comments/158400.htmlhttp://www.shnenglu.com/lvlawliet/articles/158400.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158400.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158400.html闃呰鍏ㄦ枃

LLawliet 2011-10-15 22:18 鍙戣〃璇勮
]]>
POJ3164:Command Networkhttp://www.shnenglu.com/lvlawliet/articles/158399.htmlLLawlietLLawlietSat, 15 Oct 2011 14:18:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158399.htmlhttp://www.shnenglu.com/lvlawliet/comments/158399.htmlhttp://www.shnenglu.com/lvlawliet/articles/158399.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158399.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158399.html
Command Network
Time Limit: 1000MSMemory Limit: 131072K
Total Submissions: 7267Accepted: 2160

Description

After a long lasting war on words, a war on arms finally breaks out between littleken’s and KnuthOcean’s kingdoms. A sudden and violent assault by KnuthOcean’s force has rendered a total failure of littleken’s command network. A provisional network must be built immediately. littleken orders snoopy to take charge of the project.

With the situation studied to every detail, snoopy believes that the most urgent point is to enable littenken’s commands to reach every disconnected node in the destroyed network and decides on a plan to build a unidirectional communication network. The nodes are distributed on a plane. If littleken’s commands are to be able to be delivered directly from a node A to another node B, a wire will have to be built along the straight line segment connecting the two nodes. Since it’s in wartime, not between all pairs of nodes can wires be built. snoopy wants the plan to require the shortest total length of wires so that the construction can be done very soon.

Input

The input contains several test cases. Each test case starts with a line containing two integer N (N ≤ 100), the number of nodes in the destroyed network, and M (M ≤ 104), the number of pairs of nodes between which a wire can be built. The next N lines each contain an ordered pair xi and yi, giving the Cartesian coordinates of the nodes. Then follow M lines each containing two integers i and j between 1 and N (inclusive) meaning a wire can be built between node i and node j for unidirectional command delivery from the former to the latter. littleken’s headquarter is always located at node 1. Process to end of file.

Output

For each test case, output exactly one line containing the shortest total length of wires to two digits past the decimal point. In the cases that such a network does not exist, just output ‘poor snoopy’.

Sample Input

4 6 
0 6
4 6
0 0
7 20
1 2
1 3
2 3
3 4
3 1
3 2
4 3
0 0
1 0
0 1
1 2
1 3
4 1
2 3

Sample Output

31.19 
poor snoopy

Source


瑁哥殑鏈灝忔爲褰㈠浘錛屾垜灝辨槸涓轟簡媯楠屾ā鏉?...緇撴灉榪橀敊浜?....%.2lf鍦≒OJ涓婄敤G++浼氳帿鍚嶇殑鎸傛帀錛屾墍浠ョ敤C++灝辮浜嗐?br />浠g爜錛?br />
#include <cstdio>
#include 
<cstring>
#include 
<cmath>
#include 
<algorithm>
#define MAXN 110
#define INF 1e30
using namespace std;

inline 
double sqr(double x)
{
    
return x * x;
}

struct point
{
    
double _x, _y;
    
double dist_with(const point &rh) const
    {
        
return sqrt(sqr(_x - rh._x) + sqr(_y - rh._y));
    }
} po[MAXN];

double g[MAXN][MAXN];

int pre[MAXN];
bool is_out[MAXN];
int vis[MAXN], vcnt;

double solve(int n, int root)
{
    memset(is_out, 
false, n);
    
double ans = 0;
    
while (1)
    {
        
int i, j, k;
        
for (i = 0; i < n; ++i)
            
if (i != root && !is_out[i])
            {
                pre[i] 
= i;
                
for (j = 0; j < n; ++j)
                    
if (!is_out[j] && g[pre[i]][i] > g[j][i])
                        pre[i] 
= j;
                
if (pre[i] == i) throw false;
            }
        
for (i = 0; i < n; ++i)
            
if (i != root && !is_out[i])
            {
                j 
= i;
                vis[i] 
= ++vcnt;
                
while (vis[pre[j]] != vcnt && pre[j] != root)
                {
                    j 
= pre[j];
                    vis[j] 
= vcnt;
                }
                
if (pre[j] == i)
                    
break;
            }
        
if (i == n)
        {
            
for (j = 0; j < n; ++j)
                
if (j != root && !is_out[j])
                    ans 
+= g[pre[j]][j];
            
break;
        }
        j 
= i;
        
do
        {
            is_out[j] 
= true;
            ans 
+= g[pre[j]][j];
            j 
= pre[j];
        } 
while (j != i);
        
for (int j = 0; j < n; ++j)
            
if (vis[j] == vcnt)
                
for (int k = 0; k < n; ++k)
                    
if (!is_out[k])
                    {
                        
if (g[i][k] > g[j][k])
                            g[i][k] 
= g[j][k];
                        
if (g[k][i] > g[k][j] - g[pre[j]][j] && g[k][j] != INF)
                            g[k][i] 
= g[k][j] - g[pre[j]][j];
                    }
        is_out[i] 
= false;
    }
    
return ans;
}

int main()
{
    
int n, m;
    
while (scanf("%d%d"&n, &m) != EOF)
    {
        
for (int i = 0; i < n; ++i)
            
for (int j = 0; j < n; ++j)
                g[i][j] 
= INF;
        
for (int i = 0; i < n; ++i)
            scanf(
"%lf%lf"&po[i]._x, &po[i]._y);
        
for (int i = 0; i < m; ++i)
        {
            
int a, b;
            scanf(
"%d%d"&a, &b);
            
if (a != b)
                g[a 
- 1][b - 1= po[a - 1].dist_with(po[b - 1]);
        }
        
try
        {
            printf(
"%.2lf\n", solve(n, 0));
        }
        
catch (bool)
        {
            printf(
"poor snoopy\n");
        }
    }
    
return 0;
}


LLawliet 2011-10-15 22:18 鍙戣〃璇勮
]]>
ZOJ3316錛欸amehttp://www.shnenglu.com/lvlawliet/articles/158398.htmlLLawlietLLawlietSat, 15 Oct 2011 14:17:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158398.htmlhttp://www.shnenglu.com/lvlawliet/comments/158398.htmlhttp://www.shnenglu.com/lvlawliet/articles/158398.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158398.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158398.html
浼犻侀棬錛歨ttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3726

涓閬撶湅浼煎崥寮堣鐨勯錛屽叾瀹炲氨鏄ā鏉塊鑰屽凡銆?br />
鍒嗘瀽錛?br />騫抽潰涓奛涓偣錛屼袱涓漢杞祦鍙栫偣錛岃屼笖瑙勫畾褰撳墠鍙栫殑鐐瑰拰涓婁竴涓彇鐨勭偣鐨勬浖鍝堥】璺濈瑕佸皬浜嶭錛屾墍浠ワ紝鐐瑰彲浠ョ湅鎴愪袱涓ゆ垚瀵規(guī)秷鍘匯?br />榪欎篃灝辮漿鎴愪簡涓鑸浘鍖歸厤錛屽鏋滃瓨鍦ㄥ畬緹庡尮閰嶏紝閭d箞鍚庢墜鐨勪漢鎬誨彲浠ュ彇瀹岋紝濡傛灉涓嶅瓨鍦紝閭d箞鍏堟墜鐨勪漢鍙互鎷夸竴涓绔嬬偣錛岃繖鏍風(fēng)浜屼釜浜鴻涔堟病鏈夊尮閰嶇偣錛岃涔堝彧鑳芥媶鍒頒竴涓尮閰嶅錛屼絾榪欐牱鍙堥犳垚浜嗗绔嬬偣銆?br />
緗戜笂鏈変釜浜烘嬁浜屽垎鍥懼尮閰嶈繃浜?...鐪嬫潵鏁版嵁寰堝急.....
浠g爜錛?br />
#include <cstdio>
#include 
<cstring>
#include 
<algorithm>
#include 
<iostream>
#include 
<cmath>
#define MAXN 450
using namespace std;

int x[MAXN], y[MAXN];

struct Graph
{
    
bool mat[MAXN + 1][MAXN + 1];
    
int n;

    
bool inque[MAXN + 1];
    
int que[MAXN], head, tail;

    
int match[MAXN + 1], father[MAXN + 1], base[MAXN + 1];

    
void init(int _n)
    {
        n 
= _n;
        
for (int i = 1; i <= n; ++i)
        {
            match[i] 
= 0;
            
for (int j = 1; j <= n; ++j)
                mat[i][j] 
= false;
        }
    }

    
int pop()
    {
        
return que[head++];
    }

    
void push(int x)
    {
        que[tail
++= x;
        inque[x] 
= true;
    }

    
void add_edge(int a, int b)
    {
        mat[a][b] 
= mat[b][a] = true;
    }

    
int inpath[MAXN + 1];
    
static int pcnt;

    
int find_ancestor(int u, int v)
    {
        
++pcnt;
        
while (u)
        {
            u 
= base[u];
            inpath[u] 
= pcnt;
            u 
= father[match[u]];
        }

        
while (true)
        {
            v 
= base[v];
            
if (inpath[v] == pcnt)
                
return v;
            v 
= father[match[v]];
        }
    }

    
int inblossom[MAXN + 1];
    
static int bcnt;

    
void reset(int u, int anc)
    {
        
while (u != anc)
        {
            
int v = match[u];
            inblossom[
base[v]] = bcnt;
            inblossom[
base[u]] = bcnt;
            v 
= father[v];
            
if (base[v] != anc) father[v] = match[u];
            u 
= v;
        }
    }

    
void contract(int u, int v)
    {
        
int anc = find_ancestor(u, v);
        
++bcnt;
        reset(u, anc);
        reset(v, anc);
        
if (base[u] != anc) father[u] = v;
        
if (base[v] != anc) father[v] = u;
        
for (int i = 1; i <= n; ++i)
            
if (inblossom[base[i]] == bcnt)
            {
                
base[i] = anc;
                
if (!inque[i]) push(i);
            }
    }

    
int find_augment(int start)
    {
        
for (int i = 1; i <= n; ++i)
        {
            father[i] 
= 0;
            inque[i] 
= false;
            
base[i] = i;
        }
        head 
= 0, tail = 0, push(start);
        
while (head < tail)
        {
            
int u = pop();
            
for (int v = 1; v <= n; ++v)
                
if (mat[u][v] && base[v] != base[u] && match[v] != u)
                {
                    
if (v == start || (match[v] && father[match[v]]))
                        contract(u, v);
                    
else
                    {
                        
if (father[v] == 0)
                        {
                            
if (match[v])
                            {
                                push(match[v]);
                                father[v] 
= u;
                            }
                            
else
                            {
                                father[v] 
= u;
                                
return v;
                            }
                        }
                    }
                }
        }
        
return 0;
    }

    
void augment(int finish)
    {
        
int u = finish, v, w;
        
while (u)
        {
            v 
= father[u];
            w 
= match[v];
            match[u] 
= v;
            match[v] 
= u;
            u 
= w;
        }
    }

    
int graph_max_match()
    {
        
int ans = 0;
        
for (int i = 1; i <= n; ++i)
            
if (match[i] == 0)
            {
                
int finish = find_augment(i);
                
if (finish)
                {
                    augment(finish);
                    ans 
+= 2;
                }
            }
        
return ans;
    }
} g;

int Graph :: bcnt = 0, Graph :: pcnt = 0;

int dis(int i, int j, int l)
{
    
int d;
    d 
= abs(x[i] - x[j]) + abs(y[i] - y[j]);
    
if (d <= l) return 1;
    
else return 0;
}

int main()
{
    
int n;
    
while (scanf("%d"&n) != EOF)
    {
        
int l;
        g.init(n);
        
for (int i = 1; i <= n; ++i)
            scanf(
"%d%d"&x[i], &y[i]);
        scanf(
"%d"&l);
        
for (int i = 1; i < n; ++i)
            
for (int j = i + 1; j <= n; ++j)
            {
                
if (dis(i, j, l)) g.add_edge(i, j);
            }
        
int sum;
        sum 
= g.graph_max_match();
        
if (sum == n) puts("YES");
        
else puts("NO");
    }
    
return 0;
}


LLawliet 2011-10-15 22:17 鍙戣〃璇勮
]]>
URAL1099:Work Scheduling(浠繪剰鍥懼尮閰嶏紝甯﹁姳鏍?http://www.shnenglu.com/lvlawliet/articles/158396.htmlLLawlietLLawlietSat, 15 Oct 2011 14:16:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158396.htmlhttp://www.shnenglu.com/lvlawliet/comments/158396.htmlhttp://www.shnenglu.com/lvlawliet/articles/158396.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158396.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158396.html

1099. Work Scheduling

Time Limit: 0.5 second
Memory Limit: 16 MB
There is certain amount of night guards that are available to protect the local junkyard from possible junk robberies. These guards need to scheduled in pairs, so that each pair guards at different night. The junkyard CEO ordered you to write a program which given the guards characteristics determines the maximum amount of scheduled guards (the rest will be fired). Please note that each guard can be scheduled with only one of his colleagues and no guard can work alone.

Input

The first line of the input contains one number N ≤ 222 which is the amount of night guards. Unlimited number of lines consisting of unordered pairs (ij) follow, each such pair means that guard #i and guard #j can work together, because it is possible to find uniforms that suit both of them (The junkyard uses different parts of uniforms for different guards i.e. helmets, pants, jackets. It is impossible to put small helmet on a guard with a big head or big shoes on guard with small feet). The input ends with Eof.

Output

You should output one possible optimal assignment. On the first line of the output write the even number C, the amount of scheduled guards. Then output C/2 lines, each containing 2 integers (ij) that denote that i and j will work together.

Sample

inputoutput
3
1 2
2 3
1 3
2
1 2
Problem Author: Jivko Ganev



妯℃澘棰?....涓鑸浘鍖歸厤涓昏鐪嬫ā鏉匡紝鍓╀笅鐨勫氨鏄嚜宸盰Y寤哄浘浜?....

妯℃澘錛?br />
#include <cstdio>
#include 
<cstring>
#include 
<algorithm>
#include 
<iostream>
#define MAXN 256
using namespace std;

struct Graph
{
    
bool mat[MAXN + 1][MAXN + 1];
    
int n;

    
bool inque[MAXN + 1];
    
int que[MAXN], head, tail;

    
int match[MAXN + 1], father[MAXN + 1], base[MAXN + 1];

    
void init(int _n)
    {
        n 
= _n;
        
for (int i = 1; i <= n; ++i)
        {
            match[i] 
= 0;
            
for (int j = 1; j <= n; ++j)
                mat[i][j] 
= false;
        }
    }

    
int pop()
    {
        
return que[head++];
    }

    
void push(int x)
    {
        que[tail
++= x;
        inque[x] 
= true;
    }

    
void add_edge(int a, int b)
    {
        mat[a][b] 
= mat[b][a] = true;
    }

    
int inpath[MAXN + 1];
    
static int pcnt;

    
int find_ancestor(int u, int v)
    {
        
++pcnt;
        
while (u)
        {
            u 
= base[u];
            inpath[u] 
= pcnt;
            u 
= father[match[u]];
        }

        
while (true)
        {
            v 
= base[v];
            
if (inpath[v] == pcnt)
                
return v;
            v 
= father[match[v]];
        }
    }

    
int inblossom[MAXN + 1];
    
static int bcnt;

    
void reset(int u, int anc)
    {
        
while (u != anc)
        {
            
int v = match[u];
            inblossom[
base[v]] = bcnt;
            inblossom[
base[u]] = bcnt;
            v 
= father[v];
            
if (base[v] != anc) father[v] = match[u];
            u 
= v;
        }
    }

    
void contract(int u, int v)
    {
        
int anc = find_ancestor(u, v);
        
++bcnt;
        reset(u, anc);
        reset(v, anc);
        
if (base[u] != anc) father[u] = v;
        
if (base[v] != anc) father[v] = u;
        
for (int i = 1; i <= n; ++i)
            
if (inblossom[base[i]] == bcnt)
            {
                
base[i] = anc;
                
if (!inque[i]) push(i);
            }
    }

    
int find_augment(int start)
    {
        
for (int i = 1; i <= n; ++i)
        {
            father[i] 
= 0;
            inque[i] 
= false;
            
base[i] = i;
        }
        head 
= 0, tail = 0, push(start);
        
while (head < tail)
        {
            
int u = pop();
            
for (int v = 1; v <= n; ++v)
                
if (mat[u][v] && base[v] != base[u] && match[v] != u)
                {
                    
if (v == start || (match[v] && father[match[v]]))
                        contract(u, v);
                    
else
                    {
                        
if (father[v] == 0)
                        {
                            
if (match[v])
                            {
                                push(match[v]);
                                father[v] 
= u;
                            }
                            
else
                            {
                                father[v] 
= u;
                                
return v;
                            }
                        }
                    }
                }
        }
        
return 0;
    }

    
void augment(int finish)
    {
        
int u = finish, v, w;
        
while (u)
        {
            v 
= father[u];
            w 
= match[v];
            match[u] 
= v;
            match[v] 
= u;
            u 
= w;
        }
    }

    
int graph_max_match()
    {
        
int ans = 0;
        
for (int i = 1; i <= n; ++i)
            
if (match[i] == 0)
            {
                
int finish = find_augment(i);
                
if (finish)
                {
                    augment(finish);
                    ans 
+= 2;
                }
            }
        
return ans;
    }
} g;

int Graph :: bcnt = 0, Graph :: pcnt = 0;

int main()
{
    
int n;
    scanf(
"%d"&n);
    g.init(n);
    
int a, b;
    
while (scanf("%d%d"&a, &b) != EOF)
        g.add_edge(a, b);
    printf(
"%d\n", g.graph_max_match());
    
for (int i = 1; i <= n; ++i)
        
if (g.match[i])
        {
            printf(
"%d %d\n", i, g.match[i]);
            g.match[g.match[i]] 
= 0;
        }
    
return 0;
}



LLawliet 2011-10-15 22:16 鍙戣〃璇勮
]]>
JOJ1871:Jogging Trailshttp://www.shnenglu.com/lvlawliet/articles/158388.htmlLLawlietLLawlietSat, 15 Oct 2011 14:13:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158388.htmlhttp://www.shnenglu.com/lvlawliet/comments/158388.htmlhttp://www.shnenglu.com/lvlawliet/articles/158388.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158388.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158388.html

 1871: Jogging Trails


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K5917Standard
Gord is training for a marathon. Behind his house is a park with a large network of jogging trails connecting water stations. Gord wants to find the shortest jogging route that travels along every trail at least once.

Input consists of several test cases. The first line of input for each case contains two positive integers: n <= 15, the number of water stations, and m < 1000, the number of trails. For each trail, there is one subsequent line of input containing three positive integers: the first two, between 1 and n, indicating the water stations at the end points of the trail; the third indicates the length of the trail, in cubits. There may be more than one trail between any two stations; each different trail is given only once in the input; each trail can be travelled in either direction. It is possible to reach any trail from any other trail by visiting a sequence of water stations connected by trails. Gord's route may start at any water station, and must end at the same station. A single line containing 0 follows the last test case.

For each case, there should be one line of output giving the length of Gord's jogging route.

Sample Input

4 5
1 2 3
2 3 4
3 4 5
1 4 10
1 3 12
0

Output for Sample Input

41





鍙よ佺殑鍥捐闂錛氫腑鍥介偖閫掑憳闂錛屾浘緇忓湪鏌愪釜鍥捐涔︿笂鐪嬭繃錛屼箣鍚庡氨娌℃湁涔嬪悗浜?.....
棰樼洰澶ф剰寰堢畝鍗曪細緇欎竴鏃犲悜緗戠粶N錛屼粠鐐?鍑哄彂錛屾瘡鏉¤竟鑷沖皯榪涜繃涓嬈″悗鍥炲埌鐐?銆?br />鎬濊礬錛氾紙copy鍒漢鐨勶級
1. 鍏堣В閲婁笅"搴?鐨勬蹇? 瀵逛簬鏃犲悜鍥句腑鏌愮粨鐐? 瀹冨拰n鏉¤竟鐩歌繛, 灝辯О瀹冪殑搴︿負n. (鏈夊悜鍥捐繕鍒嗗嚭搴﹀叆搴? 榪欓噷綆鍖栦簡, 涓嶇)

2. 鍙傝冩鎷夊洖璺殑姒傚康, 鏃犲悜鍥懼瓨鍦ㄦ鎷夊洖璺? 褰撳墠浠呭綋鎵鏈夌偣搴︽暟鍧囦負鍋舵暟. 
璇佹槑姣旇緝綆鍗? 鍥犱負璧板畬涓鏉″洖璺? 瀵逛簬鎵鏈夌偣鍧囪繘鍘諱竴嬈? 鍑烘潵涓嬈? 鏁? 瀵逛簬浠繪剰鐐圭殑搴︽暟,閮芥槸鎴愬鐨勫湪"娑堣?.

3. 棰樹腑鎵鎻忚堪鐨勫洖璺? 鏈夐噸澶嶇粡榪囨煇杈? 榪欐病鍏崇郴. 鐜板湪鍋囪閭掑憳鎸夐鐩姹傝蛋浜嗕竴鏉℃渶鐭殑鍥炶礬P.
閭d箞, 鎶奝鎵鏈夐噸澶嶇粡榪囩殑杈? 鎷嗗紑. 鍗沖亣璁句笁嬈$粡榪囪竟L, 鍒欐垜浠彲浠ヤ漢涓虹殑鍦ㄥ師鍥句笂澶氬姞涓ゆ潯杈? 瀵逛簬鎵鏈夐噸澶嶇粡榪囩殑杈歸兘榪欐牱鍋? 淇敼鍚庣殑鍥捐涓篏2. (鍘熷浘涓篏)
瀵逛簬G2, 閭掑憳璧扮殑鍥炶礬, 鍗充負姝ゅ浘鐨勬鎷夊洖璺? 榪欐槸閲嶇偣. (鍏跺疄寰堝ソ鎯? 鍥犱負G2涓殑姣忔潯杈歸兘浠呰閭掑憳璧拌繃涓嬈?)

4. 鍘熼棶棰樺氨鍙互杞寲涓? 濡備綍鎶奊娣誨姞涓浜涜竟, 鍙樻垚G2
鑰孏2鎵鏈夌偣搴︽暟鍧囦負鍋舵暟(榪欐槸鑲畾鐨? 鍥犱負G2瀛樺湪嬈ф媺鍥炶礬)
鏁呰漿鍖栦負, 濡備綍鎶奊涓煇浜涜竟澶嶅埗x嬈? 浠庤屾秷鐏璆涓殑濂囩偣(搴︽暟涓哄鏁扮殑鐐?.

5. 鍙兘鏈夌偣鏅? 涓句釜渚嬪瓙
鍥綠鍙湁涓や釜鐐筧鍜宐, 涓鏉¤竟榪炵潃ab, 閭d箞ab鍧囦負濂囩偣, 瑕佹秷鐏帀, 灝辨妸ab涔嬮棿榪炵嚎澶嶅埗涓嬈?鍥犱負浣犱笉鍙兘闅忎究緇欏畠鍔犱竴鏉′笉瀛樺湪鐨?.)
鐒跺悗鍙樻垚涓ゆ潯杈硅繛鐫ab. 浠嶨2鐨勮搴︾湅, 鏄鎷夊浘浜? 瀵瑰簲鎴怗, 灝辨槸鎶婅繖鏉¤竟璧頒簡涓ゆ鑰屽凡.

6. 濂囩偣鎬繪槸鎴愬鐨勮娑堢伃, 灝辯畻涓や釜濂囩偣涓嶄簰閫? 鑰屾槸緇忚繃寰堝鐐規(guī)墠鑳借繛閫? 閭d篃瑕佽繛鍑轟竴鏉¤礬寰勬潵, 浠ユ秷鐏繖瀵瑰鐐?

7. 閭e氨濂藉姙浜?鎶婃墍鏈夊鐐規(guī)壘鍑烘潵, 鐒跺悗閰嶅, 濡傛灉鏌愮閰嶅鏂瑰紡浠d環(huán)鏈灝? 鍗充負鎵姹?
榪欓噷榪樿鐢ㄤ笂floyd, 姹傛渶鐭礬

8. 閰嶅綆楁硶涔熻姣旇緝濂? 瑁哥潃閰嶅ぇ姒備細瓚呮椂, 榪欎釜鎳掑緱璇翠簡.. 濡傛灉涓嶄細, 鐩存帴鐪嬩唬鐮佸惂.

緇欑偣鎵艱娉ㄩ噴, deg璁板綍搴︽暟, mp璁板綍鏈鐭礬. u璁板綍閫掑綊鏃跺悇鐐規(guī)槸鍚﹀凡閰嶅. (鍋剁偣鐩存帴琚涓哄凡閰嶅. 閫掑綊鏃跺彧璺繃)
dfs榪斿洖鍦ㄥ綋鍓嶆縐島璁板綍鐨勯厤瀵規(guī)儏鍐典笅, 鎶婃湭閰嶅鐨勫尮閰嶅畬, 鏈灝忎唬浠鋒槸澶氬皯

榪樻槸鎻愪竴鍙ュ惂, 姣忔閰嶅鏃? 閰嶅涓殑絎竴涓彲浠ョ洿鎺ュ彇闃熷垪涓殑絎竴涓病鏈夐厤瀵圭殑鍏冪礌(鍏跺疄闅忎究鍙栭兘琛?. 絎簩涓? 寰幆涓嬈″墿涓嬬殑鍗沖彲.
鍥犱負閰嶅鏄笉鍏沖績欏哄簭鐨? 鎵浠ョ涓涓彲浠ユ兂鎬庝箞鍙栭兘琛? 涓轟簡鏂逛究, 灝辯涓涓簡.

浠g爜錛?br />
#include <cstdio>
#include 
<cstring>
#include 
<cmath>
#include 
<iostream>
#define N 17
#define inf 1 << 20
using namespace std;

int deg[N], map[N][N], u[N];
int ans, n, m;

int min(int a, int b)
{
    
if (a > b) return b;
    
return a;
}

int slove()
{
    
int i, j, rnt = inf;
    
for (i = 0; i < n; ++i)
    
if (!u[i]) break;
    
if (i == n) return 0;
    u[i] 
= 1;
    
for (j = i + 1; j < n; ++j)
    {
        
if (!u[j]) u[j] = 1, rnt = min(rnt, slove() + map[i][j]), u[j] = 0;
    }
    u[i] 
= 0;
    
return rnt;
}

int main()
{
    
while (scanf("%d"&n) && n)
    {
        memset(u, 
0sizeof(u));
        memset(deg, 
0sizeof(deg));
        
for (int i = 0; i < n; ++i)
            
for (int j = 0; j < n; ++j)
            map[i][j] 
= inf;
        ans 
= 0;
        scanf(
"%d"&m);
        
for (int i = 1; i <= m; ++i)
        {
            
int a, b, c;
            scanf(
"%d%d%d"&a, &b, &c);
            ans 
+= c;
            a
--; b--;
            deg[a]
++;
            deg[b]
++;
            map[a][b] 
= map[b][a] = min(map[a][b], c);
        }
        
for (int k = 0; k < n; ++k)
            
for (int i = 0; i < n; ++i)
                
for (int j = 0; j < n; ++j)
                {
                    map[i][j] 
= min(map[i][j], map[i][k] + map[k][j]);
                }
        
for (int i = 0; i < n; ++i)
        
if (deg[i] % 2 == 0) u[i] = 1;
        printf(
"%d\n", ans + slove());
    }
    
return 0;
}


LLawliet 2011-10-15 22:13 鍙戣〃璇勮
]]>
ZOJ2697:Electricityhttp://www.shnenglu.com/lvlawliet/articles/158387.htmlLLawlietLLawlietSat, 15 Oct 2011 14:12:00 GMThttp://www.shnenglu.com/lvlawliet/articles/158387.htmlhttp://www.shnenglu.com/lvlawliet/comments/158387.htmlhttp://www.shnenglu.com/lvlawliet/articles/158387.html#Feedback0http://www.shnenglu.com/lvlawliet/comments/commentRss/158387.htmlhttp://www.shnenglu.com/lvlawliet/services/trackbacks/158387.html
Electricity

Time Limit: 10 Seconds      Memory Limit: 32768 KB      Special Judge

After recent blackouts in some regions in North America, the government has decided to reorganize the power supply network of the continent.

The power supply network is the set of nodes, such as power plants or transformation stations, connected by transmission lines. All lines are used to transmit electricity from one node to another. For stability reasons the system is organized in such a way that there are no directed cycles.

Since the government is currently short of money due to several small peaceful militaristic operations, it cannot build new power lines for the moment. So after reorganization the same lines will be used, but some lines will have to transmit electricity in the direction opposite to the current one. To make the reorganization gentle enough, the management of the power network is planning to switch the transmission direction for exactly one line each day. Of course, no day there must be a cycle in a network, since this may cause damage to the system. The resulting network is also designed to be acyclic.

Help them to plan the reorganization.

Input

There are mutilple cases in the input file.

The first line of the input file contains n --- the number of nodes in the network, and m --- the number of transmission lines (2 <= n <= 1,000 , 1 <= m <= 10,000 ). The following m lines contain three integer numbers each. The first two give the source and the destination node for the corresponding line in the current node. The third number is 0 if the line must keep its transmission direction in the resulting network, and 1 if the direction must be reversed.

There can be several lines connecting the same pair of nodes, but due to acyclicity condition, they all transmit electricity in the same direction. This is also the reason why no line connects a node to itself.

There is an empty line after each case.

Output

First output k --- the number of days in the plan you suggest. You don't need to minimize this number, but it must not exceed 4m . After that print k integer numbers --- for each day output the number of the line that changes the transmission direction this day. If it is impossible to make the desired reorganization, output -1 instead of k .

There should be an empty line after each case.

Sample Input

4 5
1 2 0
2 3 1
2 4 1
1 4 1
4 3 0

2 2
1 2 1
1 2 1

Sample Output

3
3 2 4

-1


Source: Andrew Stankevich's Contest #9


涓閬撲笉閿欑殑鍥捐棰橈紝澶ф剰鏄粰涓涓湁鍚戠綉緇淣錛屽繀欏誨皢鍏朵腑X鏉¤竟鍙嶅悜錛岀粰鍑轟竴涓柟妗堥『搴忥紝浣垮緱鍦ㄦ墽琛屽弽鍚戠殑榪囩▼涓紝緗戠粶涓嶄細鍑虹幇鐜紝濡傛灉涓嶅瓨鍦ㄨ繖涓柟妗堬紝杈撳嚭-1.

鎬濊礬錛氶鍏堬紝鍒ゆ柇涓嶅瓨鍦ㄧ殑鎯呭喌錛?.涓や釜閲嶈竟閮借鍙嶈漿錛岄偅涔堝湪鎿嶄綔榪囩▼涓偗瀹氬嚭鐜扮幆錛?.鍦ㄥ垵濮嬬綉緇滄垨緇撴潫緗戠粶瀛樺湪鐜傚浜庣浜岀鎯呭喌錛屽彲浠ョ敤topo鎺掑簭姹備竴涓嬩袱涓綉緇滄槸鍚﹀瓨鍦ㄧ幆錛屽茍璁板綍涓媡opp搴忓垪銆?br />涔嬪悗錛屾垜浠鏋勯犳柟妗堬紝鏋勯犳柟妗堢殑榪囩▼鏈変袱涓細
1.涓涓偣鐨勫彲閫嗗叆搴﹁竟錛堣繖鍙ユ槸搴熻瘽錛屽彲閫嗚竟灝辨槸蹇呴』鏀瑰彉鐨勮竟錛岃偗瀹氬寘鍚簬鏂規(guī)錛屼絾娉ㄦ剰鏄叆搴︼級
2.榪欎釜鐐瑰繀欏諱粠緇撳熬緗戠粶鐨則opo搴忓垪浠庡悗寰鍓嶆悳绱?....錛堝噷涔變簡鍚?...錛?br />棣栧厛錛屾垜浠鏄庣櫧topo搴忓垪鐨勬ц川錛屽氨鏄簭鍒梐1,a2,a3,...,an錛岃〃紺虹殑鏄綉緇渘涓偣鐨勭嚎鎬у叧緋伙紝瀛樺湪浠繪剰鐨刬<j,浣垮緱ai -> aj錛屼篃灝辨槸錛屽鏋滅敤緗戠粶琛ㄧずtopo搴忓垪錛岄偅涔堝彧鏈夊線鍙寵竟鎸囧悜鐨勮竟銆?br />閫氳繃榪欎竴涓ц川錛屽姞涓婄綉緇淣鍓嶅悗涓ゆ鐨則opo搴忓垪錛屾垜浠笉闅懼彂鐜幫紝緇撳熬緗戠粶topo搴忓垪鐨勬渶鍚庝竴涓偗瀹氭槸鍦ㄦ搷浣滀腑澶卞幓鍑哄害鑰屼粠鍒濆鐨則opo搴忓垪闄嶄負錛堟垨鍋滅暀錛夋渶鍚庨潰錛屾墍浠ワ紝灝嗗叾鍙弽杞殑鍏ュ害杈瑰弽鍚戯紝鑲畾涓嶄細瀛樺湪鍥炲皠杈逛粠鑰屼駭鐢熺幆緇撴瀯錛屽洜姝わ紝浠庢渶鍚庝竴涓偣鍚戝墠鎼滅儲錛屾瘡嬈℃墽琛屽彲鎵ц鐨勫弽杞搷浣滐紝閭d箞涓瀹氳兘淇濇寔褰撳墠鐐圭殑涓嶅瓨鍦ㄥ洖灝勮竟銆?br />瀵逛簬涓涓偣錛屽彲瀛樺湪鍚屾椂鏀厤澶氭潯鍙弽杞竟錛屽洜涓虹瓟妗堣姹備竴嬈′竴嬈℃墽琛屽弽杞紝濡傛灉瀵逛簬鍚屼竴涓偣欏哄簭涓嶅綋鍙兘鍑虹幇鐜紝鎵浠ユ垜浠冭檻浠ヤ笅闂錛歺->y, x->z,濡傛灉鍙嶈漿錛坸,y錛変粠鑰屽鑷翠簡鐜殑鍑虹幇錛岄偅涔堝彲浠ヨ偗瀹歾->y鏄垚绔嬬殑錛岃屽湪topo鍏崇郴涓妟姣攜闈犲墠錛屾墍浠ユ垜浠浜庡悓涓涓偣杈撳嚭緇撴灉鏃訛紝瑕佹寜鐓у叾鍒濆緗戠粶鐨則opo欏哄簭錛屼粠宸﹀悜鍙寵緭鍑恒?br />鎬濊礬瀹屾瘯錛孉C錛岃瘉鏄?...鐣ヤ簡鍚э紝鎴戣瘉鏄庝簡涓鑽夌ǹ綰搞?br />娉ㄦ剰涓嶈鐢ㄧ煩闃碉紝鎴戝洜涓洪偅涓悆浜嗗嚑嬈E......
浠g爜錛?br />
#include <iostream>
#include 
<cstdio>
#include 
<cstring>
#include 
<queue>
#include 
<vector>
#define N 1100
#define M 10010
using namespace std;

int n, m;

struct edge
{
    
int u, v, next;
} et[
2][M];

int eh[2][N], tot[2];
int be[2 * N], ed[2 * N], sta[2 * N];
int deg[2][N], deg2[N];
int g[N][N];

void add(int u, int v, int i)
{
    
int t = ++tot[i];
    et[i][t].u 
= u;
    et[i][t].v 
= v;
    et[i][t].next 
= eh[i][u];
    eh[i][u] 
= t;
    deg[i][v]
++;
}

int topo(int eh[], edge et[], int que[], int deg[])
{
    
int i, j, k, top = -1, qt = 0;
    
for (i = 1; i <= n; ++i)
        deg2[i] 
= deg[i];
    
for (i = 1; i <= n; ++i)
        
if (deg2[i] == 0)
            sta[
++top] = i;
    
for (j = 1; j <= n; ++j)
    {
        
if (top == -1return 0;
        
int u = sta[top--];
        que[qt
++= u;
        
for (i = eh[u]; i != -1; i = et[i].next)
        {
            deg2[et[i].v]
--;
            
if (deg2[et[i].v] == 0) sta[++top] = et[i].v;
        }
    }
    
return 1;
}

int was[M], cnt;
void slove()
{
    
int i, j, k;
    memset(was, 
0sizeof(was));
    printf(
"%d\n", cnt);
    
for (i = n - 1; i >= 0--i)
    {
        
int u = ed[i];
        
for (j = 0; j < n; ++j)
          
if (g[u][be[j]] > 0)
          {
              
if (was[g[u][be[j]]] == 0)
              {
                  was[g[u][be[j]]] 
= 1;
                  printf(
"%d ", g[u][be[j]]);
              }
          }
    }
    
if (cnt > 0) printf("\n");
}

int main()
{
    
int i, j, k;
    
while (scanf("%d%d"&n, &m) != EOF)
    {
        memset(eh, 
-1sizeof(eh));
        memset(deg, 
0sizeof(deg));
        
for (i = 1; i <= n; ++i)
          
for (j = 1; j <= n; ++j)
            g[i][j] 
= 0;
        tot[
1= tot[0= 0;
        cnt 
= 0;
        
int flag = 1;
        
for (i = 1; i <= m; ++i)
        {
            
int a, b, c;
            scanf(
"%d%d%d"&a, &b, &c);
            add(a, b, 
0);
            
if (c)
            {
                add(b, a, 
1);
                cnt
++;
                
if (g[a][b] > 0) flag = 0;
                g[a][b] 
= i;
            }
            
else
              add(a, b, 
1);
        }
        
if (flag == 0)
        {
            printf(
"-1\n\n");
            
continue;
        }
        
int first = topo(eh[0], et[0], be, deg[0]);
        
int last = topo(eh[1], et[1], ed, deg[1]);
        
if (!(first && last))
        {
            printf(
"-1\n\n");
            
continue;
        }
        slove();
        printf(
"\n");
    }
    
return 0;
}


LLawliet 2011-10-15 22:12 鍙戣〃璇勮
]]>
国产午夜福利精品久久2021| 久久99国产精品成人欧美| 久久国产成人精品麻豆| 亚洲精品tv久久久久| 成人资源影音先锋久久资源网| 久久无码人妻精品一区二区三区| 久久人人爽人人爽人人片AV不| 国产精品成人无码久久久久久| 亚洲av成人无码久久精品| 欧美激情精品久久久久久久九九九| 久久综合国产乱子伦精品免费| 亚洲欧美国产日韩综合久久| 国内精品伊人久久久久影院对白| 国产综合久久久久| 亚洲国产精品无码久久久蜜芽 | 韩国无遮挡三级久久| 99久久夜色精品国产网站| 色婷婷狠狠久久综合五月| 久久精品国产亚洲AV不卡| 99久久国产综合精品网成人影院| 久久天天躁狠狠躁夜夜躁2O2O| 久久亚洲精品无码aⅴ大香| 亚洲国产精品无码久久九九| 久久久久国产成人精品亚洲午夜| 99久久精品费精品国产| 国产成人香蕉久久久久| 久久久久国产精品| 久久国产乱子精品免费女| 69SEX久久精品国产麻豆| 国产精品女同久久久久电影院| 亚洲AV无码一区东京热久久| 亚洲乱码精品久久久久..| 中文字幕无码免费久久| 亚洲va久久久噜噜噜久久天堂| 亚洲国产精品无码久久久蜜芽| 久久SE精品一区二区| 国产偷久久久精品专区 | 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久男人Av资源网站无码软件 | 国产成人精品久久亚洲高清不卡| 亚洲精品国产成人99久久|