General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
62841201 Practice:
Zory
599E - 73 C++14 (GCC 6-32) Accepted 124 ms 988 KB 2019-10-18 05:50:27 2019-10-18 05:50:27
→ Source
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const T &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=13,M=bin(N)+10;

    int n,lg[M];vc<int> son[N];
    ll ff[N][M];bool done[N][M];

    struct Lim{int a,b,c;}lim[110];int q,m;pr edge[N];
    #define in(x,S) (((S)&bin(x))>0)
    bool check(int x,int A,int B){
        fo(i,1,q)
        {
            if(lim[i].c==x and in(lim[i].a,A) and in(lim[i].b,A)) return 0;
            if(lim[i].c!=x and in(lim[i].a,A) and in(lim[i].b,B)) return 0;
            if(lim[i].c!=x and in(lim[i].a,B) and in(lim[i].b,A)) return 0;
        }
        return 1;
    }
    bool check2(int x,int y,int A)
    {
        fo(i,1,m)
        {
            if(x==edge[i].FR and y==edge[i].SE) continue;if(x==edge[i].SE and y==edge[i].FR) continue;
            if(in(edge[i].FR,A)^in(edge[i].SE,A)) return 0;
        }return 1;
    }
    ll f(int x,int S)
    {
        if(done[x][S]) return ff[x][S];
        if(S==0) {done[x][S]=1;return ff[x][S]=1;}

        ll ans=0;int mi=(S&-S);
        if(check(x,mi,S^mi^bin(x)) and check2(x,lg[mi],mi))
            ans+=f(lg[mi],0)*f(x,S^mi);
        for(int s2=S^mi;s2>0;s2=(s2-1)&(S^mi)) if(check(x,s2|mi,S^(s2|mi)^bin(x)))
            fo(y,0,n-1) if((s2|mi)&bin(y) and check2(x,y,s2|mi))
                ans+=f(y,(s2|mi)^bin(y))*f(x,S^(s2|mi));
        done[x][S]=1;return ff[x][S]=ans;
    }
    void main()
    {
        n=qread(),m=qread(),q=qread();
        fo(i,0,n-1) lg[bin(i)]=i;
        fo(i,1,m)
        {
            int x=qread()-1,y=qread()-1;
            edge[i]=MP(x,y);
        }
        fo(i,1,q)
        {
            int x=qread()-1,y=qread()-1,z=qread()-1;
            lim[i]=(Lim){x,y,z};if(x==y and x!=z){puts("0");return;}
        }
        write(f(0,bin(n)-2));
    }
};//(ans+MOD)%MOD
signed main()
{
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    srand(time(0));
    mine::main();
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details