Submission #528522

# Submission time Handle Problem Language Result Execution time Memory
528522 2022-02-20T13:02:11 Z Rafi22 Šarenlist (COCI22_sarenlist) C++14
110 / 110
65 ms 452 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

vector<int>G[67];
ll p[67];
int d[67];
int o[67];
ll ile[(1<<15)+7];
int is[67];
int r[20];
int n,m,k;

void dfs(int v)
{
    for(auto u:G[v])
    {
        if(u==o[v]) continue;
        d[u]=d[v]+1;
        o[u]=v;
        dfs(u);
    }
}

void Union(int u,int v)
{
    for(int i=0;i<m;i++) if(r[i]==v) r[i]=u;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>n>>m>>k;
    p[0]=1;
    for(int i=1;i<=n;i++) p[i]=p[i-1]*(ll)k%mod;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(1);
    vector<pair<int,int>>V(m);
    for(int i=0;i<m;i++) cin>>V[i].st>>V[i].nd;
    for(int l=0;l<(1<<m);l++)
    {
        memset(is,-1,sizeof is);
        for(int i=0;i<m;i++) r[i]=i;
        for(int i=0;i<m;i++)
        {
            if(!((1<<i)&l)) continue;
            int a=V[i].st,b=V[i].nd;
            while(a!=b)
            {
                if(d[a]<d[b]) swap(a,b);
                if(is[a]!=-1) Union(r[is[a]],r[i]);
                else is[a]=r[i];
                a=o[a];
            }
        }
        int c=0;
        for(int i=2;i<=n;i++) if(is[i]==-1) c++;
        set<int>S;
        for(int i=0;i<m;i++)
        {
            if(!((1<<i)&l)) continue;
            S.insert(r[i]);
        }
        ile[l]=p[c+sz(S)];
    }
    for(int i=m-1;i>=0;i--)
    {
        for(int j=(1<<m)-1;j>=0;j--)
        {
            if(!(j&(1<<i)))
            {
                ile[j]-=ile[j^(1<<i)];
                if(ile[j]<0) ile[j]+=mod;
            }
        }
    }
    cout<<ile[0];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 5 ms 332 KB Output is correct
6 Correct 6 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 6 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 17 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 16 ms 332 KB Output is correct
31 Correct 4 ms 452 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 9 ms 368 KB Output is correct
36 Correct 65 ms 452 KB Output is correct
37 Correct 30 ms 412 KB Output is correct