Submission #531703

# Submission time Handle Problem Language Result Execution time Memory
531703 2022-03-01T10:12:28 Z Killer2501 Šarenlist (COCI22_sarenlist) C++14
0 / 110
1 ms 332 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, int>
#define fi first
#define se second
using namespace std;
const int N = 65;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
int n, lab[N], tong, d[N], t, c[N], h[N], k, P[N][8], in[N], out[N], ntime, cnt;
int ans, m, a[N], b[N];
vector<int> adj[N];
vector<pll> vi;
string s;
bool vis[N];
struct edge
{
    int x, y, z;
}e[N];
void add(int& x, int y)
{
    x += y;
    if(x >= mod)x -= mod;
}
void dfs(int u, int p = 0)
{
    in[u] = ++ntime;
    P[ntime][0] = u;
    for(int v: adj[u])
    {
        if(v == p)continue;
        h[v] = h[u]+1;
        dfs(v, u);
        out[u] = ++ntime;
        P[ntime][0] = u;
    }
}
int get(int l, int r)
{
    if(l > r)swap(l, r);
    int log = log2(r-l+1);
    if(h[P[l][log]] < h[P[r-(1<<log)+1][log]])return P[l][log];
    return P[r-(1<<log)+1][log];
}
void cal(int u, int p = 0)
{
    bool ok = false;
    for(int v: adj[u])
    {
        if(v == p)continue;
        cal(v, u);
        c[u] += c[v];
        ok |= (c[v] > 0);
    }
    if(c[u] == 0)
    {
        if(u > 1)++tong;
        if(ok)++tong;
    }
}
void sol()
{
    cin >> n >> m >> k;
    for(int i = 1; i < n; i ++)
    {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    d[0] = 1;
    for(int i = 1; i < n; i ++)d[i] = 1ll * d[i-1] * k % mod;
    dfs(1);
    for(int j = 1; j < 8; j ++)
    {
        for(int i = 1; i+(1<<j)-1 <= ntime; i ++)
        {
            if(h[P[i][j-1]] < h[P[i+(1<<(j-1))][j-1]])P[i][j] = P[i][j-1];
            else P[i][j] = P[i+(1<<(j-1))][j-1];
        }
    }
    for(int i = 0; i < m; i ++)
    {
        cin >> e[i].x >> e[i].y;
        e[i].z = get(in[e[i].x], in[e[i].y]);
    }
    for(int mask = 0; mask < (1<<m); mask ++)
    {
        fill_n(c, n+1, 0);
        for(int i = 0; i < m; i ++)
        {
            if(mask >> i & 1)
            {
                ++c[e[i].x];
                ++c[e[i].y];
                c[e[i].z] -= 2;
            }
        }
        tong = 0;
        cal(1);
        //cout << mask <<" "<< __builtin_popcount(mask) <<" "<<tong << '\n';
        if((__builtin_popcount(mask))&1)add(ans, mod-d[tong]);
        else add(ans, d[tong]);
    }
    cout << ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}
/*
1234
21
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:122:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -