Title Link: Http://codeforces.com/contest/711/problem/D
Lights Out tomorrow pits ...
1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> + using namespacestd; - #defineFr First + #defineSC Second A #defineCL Clear at #defineBUG puts ("Here!!!") - #defineW (a) while (a--) - #definePB (a) push_back (a) - #defineRint (a) scanf ("%d", &a) - #defineRll (a) scanf ("%i64d", &a) - #defineRs (a) scanf ("%s", a) in #defineCIN (a) CIN >> a - #defineFRead () freopen ("in", "R", stdin) to #defineFWrite () freopen ("Out", "w", stdout) + #defineRep (i, Len) for (int i = 0; i < (len); i++) - #defineFor (I, A, Len) for (int i = (a); I < (len); i++) the #defineCls (a) memset ((a), 0, sizeof (a)) * #defineCLR (A, X) memset ((a), (x), sizeof (a)) $ #defineFull (a) memset ((a), 0x7f7f7f, sizeof (a))Panax Notoginseng #defineLRT RT << 1 - #defineRRT RT << 1 | 1 the #definePi 3.14159265359 + #defineRT return A #defineLowbit (x) x & (-X) the #defineONECNT (x) __builtin_popcount (x) +typedefLong LongLL; -typedefLong DoubleLD; $typedef unsignedLong LongULL; $typedef pair<int,int>PII; -typedef pair<string,int>psi; -typedef PAIR<LL, Ll>PLL; thetypedef map<string,int>MSI; -typedef vector<int>VI;Wuyitypedef vector<ll>VL; thetypedef vector<vl>VVL; -typedef vector<BOOL>vb; Wu - Const intMAXN =200200; About ConstLL mod = 1e9+7; $ LL ret; - -typedefstructEdge { - intu; A intv; + intNext; theEdge () {next =-1; } - }edge; $ the intHEAD[MAXN], ecnt; the Edge EDGE[MAXN]; the intN, M; the - intbcnt, Dindex; in intDFN[MAXN], LOW[MAXN]; the intSTK[MAXN], top; the intBELONG[MAXN]; About int inch[MAXN], out[MAXN]; the BOOLINSTK[MAXN]; the intCNT[MAXN]; the + voidinit () { -Memset (Edge,0,sizeof(Edge)); theMemset (Head,-1,sizeof(head));Bayimemset (INSTK,0,sizeof(INSTK)); thememset (DFN,0,sizeof(DFN)); thememset (Low,0,sizeof(Low)); -Memset (Belong,0,sizeof(belong)); -Memsetinch,0,sizeof(inch)); theMemset out,0,sizeof( out)); theecnt = top = bcnt = Dindex =0; the } the - voidAdde (intUuintvv) { theEDGE[ECNT].U =UU; theEDGE[ECNT].V =VV; theEdge[ecnt].next =Head[uu];94Head[uu] = ecnt++; the } the the voidTarjan (intu) {98 intv =u; AboutDfn[u] = Low[u] = + +Dindex; -Stk[++top] =u;101Instk[u] =1;102 for(inti = Head[u]; ~i; I=Edge[i].next) {103v =edge[i].v;104 if(!Dfn[v]) { the Tarjan (v);106Low[u] =min (Low[u], low[v]);107 }108 Else if(Instk[v]) low[u] =min (Low[u], dfn[v]);109 } the if(Dfn[u] = =Low[u]) {111bcnt++; the Do {113v = stk[top--]; theINSTK[V] =0; theBELONG[V] =bcnt; thecnt[bcnt]++;117} while(V! =u);118 }119 } - 121 ll Quickmul (ll X, ll N) {122LL ans =1;123 while(n) {124 if(N &1) ans = (ans * x)%MoD; thex = x * x%MoD;126N >>=1;127 } - returnans;129 } the 131 the intMain () {133 //FRead ();134 while(~Rint (n)) {135RET =1; Cls (CNT);136 init ();137 intv;138for (I,1, n+1) {139 Rint (v); $ Adde (i, v);141 }142for (I,1, n+1)if(!Dfn[i]) Tarjan (i);143LL tmp =0;144for (I,1, bcnt+1) {145 if(Cnt[i] >1) {146RET = (ret * (Quickmul (2, Cnt[i])-2+MOD))%MoD;147TMP = (tmp + cnt[i])%MoD;148 }149 } MaxRET = (ret * QUICKMUL (2, n-tmp))%MoD;151cout << ret <<Endl; the }153Rt0;154}
[CF711D] Directed Roads (Strong Unicom component, count)