比赛 20110730 评测结果 AAWWAWWWWW
题目名称 朦胧之旅 最终得分 30
用户昵称 .Xmz 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-07-30 09:02:00
显示代码纯文本
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8. int n,m,S,T,pn;
  9. int d[10001],vd[10001];
  10. bool y[5001];
  11.  
  12. struct edge
  13. {
  14. int t,c;
  15. edge *next,*op;
  16. }E[100001],*V[10001];
  17. int eh;
  18. inline void addedge(int a,int b,int c)
  19. {
  20. E[++eh].next=V[a]; V[a]=E+eh; V[a]->t=b; V[a]->c=c;
  21. E[++eh].next=V[b]; V[b]=E+eh; V[b]->t=a; V[b]->c=0;
  22. V[a]->op=V[b]; V[b]->op=V[a];
  23. }
  24. void init()
  25. {
  26. int s=0,a,b,c;S=0;T=10000;
  27. d[S]=3;
  28. scanf("%d%d%d",&n,&m,&s);
  29. for (;s;--s)
  30. {
  31. scanf("%d%d%d",&a,&b,&c);
  32. if (!y[a]) {d[a]=2;addedge(S,a,1);}
  33. if (!y[b]) {d[b]=1;addedge(b,T,1);}
  34. y[a]=y[b]=true;
  35. if (c!=0) addedge(a,b,1);
  36. }
  37. }
  38.  
  39. int dfs(int u,int flow)
  40. {
  41. if (u==T) return flow;
  42. int now=0;
  43. for (edge *e=V[u];e;e=e->next)
  44. if (e->c && d[e->t]+1==d[u])
  45. {
  46. int t=dfs(e->t,min(e->c,flow-now));
  47. if (t)
  48. {
  49. e->c -= t;
  50. e->op->c += t;
  51. now += t;
  52. if (flow==now) return now;
  53. }
  54. }
  55. if (--vd[d[u]]==0) d[S]=pn;
  56. if (d[S]>=pn) return now;
  57. vd[++d[u]]++;
  58. return now;
  59. }
  60.  
  61. void solve()
  62. {
  63. int flow=n;pn=n+2;
  64. while (d[S]<pn)
  65. {
  66. flow-=dfs(S,flow);
  67. }
  68. printf("0 %d\n",flow);
  69. }
  70.  
  71. int main()
  72. {
  73. freopen("lovetravel.in","r",stdin);
  74. freopen("lovetravel.out","w",stdout);
  75. init();
  76. solve();
  77. return 0;
  78. }