2768: [JLOI2010]冠軍調查
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 826 Solved: 556
Description
一年一度的歐洲足球冠軍聯賽已經進入了淘汰賽階段。隨着衛冕冠軍巴薩羅那的淘汰,英超勁旅切爾西成爲了頭號熱門。新浪體育最近在吉林教育學院進行了一次大規模的調查,調查的內容就是關於切爾西能否在今年問鼎歐洲冠軍。新浪體育的記者從各個院系中一共抽取了n位同學作爲參與者,大家齊聚一堂,各抒己見。每一位參與者都將發言,闡述自己的看法。參與者的心裏都有一個看法,比如FireDancer認爲切爾西不可能奪冠,而WaterDancer認爲切爾西一定問鼎。但是因爲WaterDancer是FireDancer的好朋友,所以可能FireDancer爲了遷就自己的好朋友,會在發言中支持切爾西。也就是說每個參與者發言時闡述的看法不一定就是心裏所想的。現在告訴你大家心裏的想法和參與者的朋友網,希望你能安排每個人的發言內容,使得違心說話的人的總數與發言時立場不同的朋友(對)的總數的和最小。
Input
第一行兩個整數n和m,其中n(2≤n≤300)表示參與者的總數,m(0≤m≤n(n-1)/2)表示朋友的總對數。
第二行n個整數,要麼是0要麼是1。如果第i個整數的值是0的話,表示第i個人心裏認爲切爾西將與冠軍無緣,如果是1的話,表示他心裏認爲切爾西必將奪魁。
下面m行每行兩個不同的整數,i和j(1≤i, j≤n)表示i和j是朋友。注意沒有一對朋友會在輸入中重複出現。朋友關係是雙向的,並且不會傳遞。
Output
只有一個整數,爲最小的和。
Sample Input
3 3
1 0 0
1 2
1 3
2 3
Sample Output
1
HINT
最好的安排是所有人都在發言時說切爾西不會奪冠。這樣沒有一對朋友的立場相左,只有第1個人他違心說了話。
Source
頹了好久了QAQ....寫個水題騙一下訪問量QAQ...
空間是按要求開的RE了什麼鬼...再開的更大一點A掉了什麼鬼....
什麼鬼...
和善意的投票是一道題目QAQ…
什麼?沒有這個題解...
我怎麼會告訴你我當時在借鑑(chao)黃學長的Code…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/************************************************************** Problem:
2768 User:
xw_xztq Language:
C++ Result:
Accepted Time:40
ms Memory:2040
kb ****************************************************************/ #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int maxn=320,maxm=maxn*maxn,inf=(1<<30)-1; struct data{ int to,next,w;}e[maxm]; int head[maxn],n,m,ans,dis[maxn],cnt=1,S,T; void ins( int u, int v, int w){cnt++;e[cnt].to=v;e[cnt].next=head[u];head[u]=cnt;e[cnt].w=w;} //dinic()------- bool bfs() { memset (dis,-1, sizeof (dis)); dis[S]=0; queue< int >
q; q.push(S); while (!q.empty()) { int x=q.front();q.pop(); for ( int i=head[x];i;i=e[i].next) { if (dis[e[i].to]!=-1||!e[i].w) continue ; dis[e[i].to]=dis[x]+1; q.push(e[i].to); } } return dis[T]!=-1; } int dfs( int x, int f) { if (x==T||!f) return f; int w,used=0; for ( int i=head[x];i;i=e[i].next) if (dis[e[i].to]==dis[x]+1&&e[i].w) { w=dfs(e[i].to,min(f-used,e[i].w)); e[i].w-=w;e[i^1].w+=w; used+=w; if (used==f) return f; } if (!used)dis[x]=-1; return used; } //--------- int main() { scanf ( "%d%d" ,&n,&m); S=n+1;T=n+2; for ( int i=1;i<=n;i++) { int x; scanf ( "%d" ,&x); if (x) { ins(S,i,1); ins(i,S,0); } else { ins(i,T,1); ins(T,i,0); } } for ( int i=1;i<=m;i++) { int u,v; scanf ( "%d%d" ,&u,&v); ins(u,v,1);ins(v,u,1); } while (bfs()) ans+=dfs(S,inf); printf ( "%d\n" ,ans); return 0; }
|