HDU 3715 Go deeper two points + 2-sat

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Topic:

http://acm.hdu.edu.cn/showproblem.php?pid=3715

Test instructions

Given a recursive pseudo-code, ask to perform the deepest number of recursion for this pseudo-code

Ideas:

Two-minute enumeration of the answer with 2-SAT to determine whether it is feasible. The concrete map is as follows: if c[i] = = 0, then a[i] or b[i], if c[i] = = 1, then (A[i] and b[i]) or (~a[i] and ~b[i]), if c[i] = = 2, then not (A[i] and b[i]), and then strongly connected Deflation point determine if I and ~i are within the same ring

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cmath>using namespace STD;Const intN =410;Const DoubleEPS =1e-8;structedge{intTo, next;} g[n*n*2];intCNT, Head[n], cnt1, head1[n];intDfn[n], Low[n], scc[n], St[n], top, num, idx;intA[n*n], B[n*n], c[n*n];BOOLVis[n];intN, M;voidAdd_edge (intVintu) {g[cnt].to = u, G[cnt].next = Head[v], head[v] = cnt++;}voidInit () {memset(Head,-1,sizeofHead);memset(DFN,-1,sizeofDFN);memset(Vis,0,sizeofVIS); top = num = IDX = CNT =0;}voidTarjan (intV) {Dfn[v] = low[v] = ++idx; VIS[V] =true, st[top++] = v;intU for(inti = head[v]; I! =-1; i = g[i].next) {u = g[i].to;if(Dfn[u] = =-1) {Tarjan (U);        Low[v] = min (Low[v], low[u]); }Else if(Vis[u]) low[v] = min (Low[v], dfn[u]); }if(Dfn[v] = = Low[v]) {num++; Do{u = st[--top]; Vis[u] =false;        SCC[U] = num; } while(U! = v); }}BOOLWorkintMID) {init (); for(inti =0; I < mid; i++) {if(C[i] = =0) {Add_edge (A[i] + N, b[i]), Add_edge (B[i] + N, a[i]); }Else if(C[i] = =1) {Add_edge (A[i], b[i]), Add_edge (B[i], a[i]);        Add_edge (A[i] + N, B[i] + N), Add_edge (B[i] + N, A[i] + N); }Else if(C[i] = =2) {Add_edge (A[i], b[i] + N), Add_edge (B[i], a[i] + N); }    } for(inti =0; I <2*n; i++)if(Dfn[i] = =-1) Tarjan (i); for(inti =0; I < n; i++)if(Scc[i] = = Scc[i+n])return false;return true;}intMain () {intTscanf("%d", &t); while(t--) {scanf("%d%d", &n, &m); for(inti =0; I < m; i++)scanf("%d%d%d", &a[i], &b[i], &c[i]);intL =0, r = m, res; while(L <= R) {intMid = (L + r)/2;if(Work (mid)) L = mid +1, res = mid;ElseR = Mid-1; }printf("%d\n", res); }return 0;}
Related Article

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.