"Bzoj" 2140 stable marriage

Source: Internet
Author: User

"parsing" Hash, discretization, Tarjan

Analysis
For each name, the first discretization is numbered.
With hash or other, not the most basic on the line, otherwise O (n^2l) will explode.
Then please refer to: http://www.cnblogs.com/Randolph87/p/3757817.html

[Spit Groove]
Rarely spit groove, do this problem unexpectedly did a morning, began to force the marking, and then always tle.
The data range of the intermediate map is less open n, and several times WA has been tried.
This is not a water problem, why it is a difficult to accept ...

Summary
To find the necessary side of the complete matching of the binary graph, there is no augmented ring in the ①. O (n^2) ② directly try to delete to follow Hungery find complete match O (n^3).

[Code]
#include <cstdio> #include <cstring> #include <cstdlib>using namespace std;typedef unsigned long long ull;const int n=8002;const int m=20001;const int l=12;const int t=37;const int lmt=100009;int n,m;struct G{int v,nxt;} Map[m+n];int tt,hd[n];int dfn[n],pre[n],ct;int edge[n][2];int v[n],color[n],stk[n],cc;char t[L];struct T{char S[L]; int NXT;} Hash[n];int num,hh[lmt];inline void ins (int u,int v) {map[++tt].v=v;map[tt].nxt=hd[u];hd[u]=tt;} void Tarjan (int now) {dfn[now]=pre[now]=++ct;stk[++stk[0]]=now,v[now]=1;for (int k=hd[now];k;k=map[k].nxt) {if (V[map [k].v]==2) Continue;if (v[map[k].v]==1) {if (Pre[map[k].v]<dfn[now]) dfn[now]=pre[map[k].v];continue;} Tarjan (MAP[K].V); if (Dfn[map[k].v]<dfn[now]) DFN[NOW]=DFN[MAP[K].V];} if (Pre[now]==dfn[now]) {cc++;for (; stk[stk[0]]!=now;stk[0]--) color[stk[stk[0]]]=cc,v[stk[stk[0]]]=2;color[stk[ STK[0]]]=CC; v[stk[stk[0]--]]=2;}} inline ULL h (void) {ULL sum=0; int Lt=strlen (t); for (int i=0;i<lt;i++) sum=sum*t+t[i]-' 0 '; return sum;} int POs (void) {int key=h ()%lmt;for (int k=hh[key];k;k=hash[k].nxt) if (!strcmp (hash[k].s,t)) return K;memmove (HASH[++NUM].S , t,sizeof t); Hash[num].nxt=hh[key];return Hh[key]=num;} int main (void) {int t1,t2;scanf ("%d", &n), for (int i=1;i<=n;i++) {scanf ("%s", T), T1=pos (); scanf ("%s", T); T2=pos ( ); Edge[i][0]=t1,edge[i][1]=t2;ins (T1,T2);} scanf ("%d", &m), for (int i=1;i<=m;i++) {scanf ("%s", T), T1=pos (); scanf ("%s", T); T2=pos (); Ins (t2,t1);} for (int i=1;i<=n;i++) if (!v[edge[i][0]) Tarjan (edge[i][0]), for (int i=1;i<=n;i++) printf ("%s\n", Color[edge[i] [0]] ==COLOR[EDGE[I][1]]? " Unsafe ":" Safe "); return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Bzoj" 2140 stable marriage

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.