bzoj3346:ural1811 Dual Sim Phone

Source: Internet
Author: User

First, the side to go heavy, then there is $n\geq\sqrt{m}$.

Then the two-point answer, converted to determine whether there are two points of their out-side set of sets for the complete set.

Then these two points must satisfy $deg_x+deg_y\geq n$.

$deg_x\geq deg_y$ may be set, then there is $deg_x\times 2\geq n$.

Consider enumerating $x$, with a maximum of $o (\frac{m}{n}) $ $x$.

To enumerate $y$ again, there are two kinds of decision algorithms:

$1.$ $f[i][j]$ Indicates whether $i$ is not pointing to $j$, so long as there is $f[x][j]\ and\ f[y][j]=true$ is not feasible.

can be used to calculate the time complexity of $o (\frac{nm}{32}) $.

$2.$ enumerates all the out edges of the $y$ and determines whether or not it appears in $x$ by a timestamp.

Time Complexity $o (\frac{m^2}{n}) $.

Set $s$ as the threshold value, when $n\leq S $ is used algorithm 1, otherwise, the algorithm 2, there is $\frac{sm}{32}\leq\frac{m^2}{s}$.

When $s$ takes $\sqrt{\frac{m}{32}}$, it obtains the optimal complexity of $o (M\sqrt{\frac{m}{32}}) $.

Total time complexity $o (M\log m\sqrt{\frac{m}{32}}) $.

#include <cstdio> #include <algorithm>const int n=10005,m=100010;int n,m,u,i,j,k,a[m],st[n],en[n],d[n],v [n],t,l,r,mid,ans;unsigned int f[2048][64];struct e{int x, Y, Z;}  e[m];inline BOOL CMP (const E&a,const e&b) {if (a.x!=b.x) return a.x<b.x;  if (A.Y!=B.Y) return a.y<b.y; return a.z<b.z;} inline void Read (int&a) {char c;while (!) ( ((C=getchar ()) >= ' 0 ') && (c<= ' 9 ')); a=c-' 0 '; while (((C=getchar ()) >= ' 0 ') && (c<= ' 9 ')) (a*= Ten) +=c-' 0 ';}      BOOL Check (int mid) {if (n>2048) {for (i=0;i<n;i++) {d[i]=0;    for (j=st[i];j<en[i];j++) if (e[j].z<=mid) d[i]++;    } for (i=0;i<n;i++) v[i]=-1;      for (i=0;i<n;i++) if (d[i]*2>=n) {for (k=st[i];k<en[i];k++) if (e[k].z<=mid) v[e[k].y]=i;        for (j=0;j<n;j++) if (D[i]+d[j]>=n&&d[i]>=d[j]) {t=d[i];        for (k=st[j];k<en[j];k++) if (e[k].z<=mid&&v[e[k].y]<i) t++;      if (t==n) return 1; }}}else{for (i=0;i<n;i++) {for (j=0;j<u;J + +) f[i][j]=~0u;      f[i][u]=0;    for (j=u<<5;j<n;j++) f[i][j>>5]|=1u<< (j&31);      } for (i=0;i<n;i++) {d[i]=0;    for (j=st[i];j<en[i];j++) if (e[j].z<=mid) d[i]++,f[i][e[j].y>>5]^=1u<< (e[j].y&31);        } for (i=0;i<n;i++) if (d[i]*2>=n) {for (j=0;j<n;j++) if (D[i]+d[j]>=n&&d[i]>=d[j]) {t=1;        for (k=0;k<=u;k++) if (F[i][k]&f[j][k]) {t=0;break;}      if (t) return 1; }}} return 0;} int main () {read (n), read (m);  u= (n-1) >>5;    for (i=1;i<=m;i++) {read (e[i].x), read (E[I].Y), read (E[I].Z);  e[i].x--, e[i].y--;  } std::sort (E+1,E+M+1,CMP); for (i=1;i<=m;i++) if (i==1| | e[i].x!=e[i-1].x| |  E[I].Y!=E[I-1].Y) E[++j]=e[i];  for (m=j,i=1;i<=m;i++) a[i]=e[i].z;  Std::sort (a+1,a+m+1);    for (i=0,j=1;i<n;i++) {st[i]=j;    while (j<=m&&e[j].x==i) j + +;  En[i]=j;  } l=1,r=m;  while (l<=r) if (check (a[mid= (l+r) >>1]) r= (ans=mid) -1;else l=mid+1; if (!ans) puts ("No solution"); else printf ("%d ", A[ans]); return 0;}

  

bzoj3346:ural1811 Dual Sim Phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.