Submission #931522


Source Code Expand

// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;
#define int long long
const int N = (int) 205, mod = (int) 1e9 + 7;
int dp[N][N], cnt[N], par[N], cut[N], comb[N][N], h[N], mark[N], s[N], t[N], low[N];
vector<int> ecp[N], comp[N], ver, adj[N], ed;
stack<int> st;
/*
   int dfs(int v, int p = -1, int ep = -1) {
   if (mark[v]++) return h[v];
   ver.push_back(v);
   h[v] = (p == -1? 0: h[p] + 1);
   int res = h[v];
   for (int e : adj[v]) {
   if (e != ep) {
   int u = s[e] ^ t[e] ^ v;
   res = min(res, dfs(u, v, e));
   }
   }
   if (ep != -1 && res == h[v]) {
   cut[ep] = 1;
   }
   return res;
   }*/
int dfs_bcc(int v, int p = -1) {
    if (mark[v]++) {
        return h[v];
    }
    h[v] = (p == -1? 0: h[p] + 1);
    low[v] = h[v];
    st.push(v);
    for (int e : adj[v])
        low[v] = min(low[v], dfs_bcc(s[e] ^ t[e] ^ v, v));
    if (h[v] - 1 == low[v]) {
        while (st.top() != v) {
            int u = st.top(); st.pop();
            comp[u].push_back(v);
        }
        comp[v].push_back(v);
        st.pop();
        comp[p].push_back(v);
    }
    return low[v];
}
int marke[N];
int pw(int a, int b) { return b != 0? pw(a * 1ll * a % mod, b >> 1) * 1ll * (b & 1? a : 1) % mod: 1; }
int g[N], n, m, k;
int cycle(int x) {
    long long res = 0;
    memset(g, 0, sizeof g);
    for (int d = x; d >= 1; --d) if (x % d == 0) {
        g[d] = pw(k, x / d);
        for (int p = x; p > d; --p) if (p % d == 0) {
            g[d] = (g[d] - g[p] + mod) % mod;
        }
    }
    for (int d = 1; d <= x; ++d) if (x % d == 0)
        res = (res + g[d] * 1ll * pw(x / d, mod - 2)) % mod;
    return res;
}
int find(int x) { return x == par[x]? x: par[x] = find(par[x]); }
void unite(int u, int v) { par[find(u)] = find(v); }
int cnte[N], cntv[N];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j <= i; ++j) {
            comb[i][j] = 1;
            if (i != j && j > 0) {
                comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
            }
        }   
    for (int i = 0; i < m; ++i) {
        int &u = s[i], &v = t[i];
        cin >> u >> v;
        --u, --v;
        adj[u].push_back(i);
        adj[v].push_back(i);
    }
    long long res = 1;
    for (int v = 0; v < n; ++v) if (!mark[v]) {
        dfs_bcc(v);
    }
    for (int e0 = 0; e0 < m; ++e0) {
        int flag = 1;
        for (int a : comp[s[e0]]) {
            for (int b : comp[t[e0]])
                if (a == b) {
                    ecp[a].push_back(e0);
                    flag = 0;
                    break;
                }
            if (!flag) break;
        }
    }
    for (int v = 0; v < n + n; ++v) if (ecp[v].size()) {
        vector<int> vv;
        for (int e : ecp[v]) {
            vv.push_back(s[e]);
            vv.push_back(t[e]);
        }
        sort(vv.begin(), vv.end());
        vv.resize(unique(vv.begin(), vv.end()) - vv.begin());
        int vc = vv.size();
        int ec = ecp[v].size();
        if (ec == vc) {
            res = res * 1ll * cycle(vc) % mod;
        } else
            res = res * 1ll * comb[ec + k - 1][k - 1] % mod;
    }
    for (int e = 0; e < m; ++e) if (cut[e]) {
        res = res * 1ll * k % mod;
    }
    cout << res << endl;
}

Submission Info

Submission Time
Task F - Painting Graphs with AtCoDeer
User Reyna
Language C++14 (GCC 5.4.1)
Score 1300
Code Size 3731 Byte
Status AC
Exec Time 3 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1300 / 1300
Status
AC × 3
AC × 64
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt, 1_047.txt, 1_048.txt, 1_049.txt, 1_050.txt, 1_051.txt, 1_052.txt, 1_053.txt, 1_054.txt, 1_055.txt, 1_056.txt, 1_057.txt, 1_058.txt, 1_059.txt, 1_060.txt, 1_061.txt, 1_062.txt, 1_063.txt
Case Name Status Exec Time Memory
0_000.txt AC 3 ms 640 KB
0_001.txt AC 3 ms 640 KB
0_002.txt AC 3 ms 640 KB
1_003.txt AC 3 ms 640 KB
1_004.txt AC 3 ms 640 KB
1_005.txt AC 3 ms 640 KB
1_006.txt AC 3 ms 640 KB
1_007.txt AC 3 ms 640 KB
1_008.txt AC 3 ms 640 KB
1_009.txt AC 3 ms 640 KB
1_010.txt AC 3 ms 640 KB
1_011.txt AC 3 ms 640 KB
1_012.txt AC 3 ms 640 KB
1_013.txt AC 3 ms 640 KB
1_014.txt AC 3 ms 640 KB
1_015.txt AC 3 ms 640 KB
1_016.txt AC 3 ms 640 KB
1_017.txt AC 3 ms 640 KB
1_018.txt AC 3 ms 640 KB
1_019.txt AC 3 ms 640 KB
1_020.txt AC 3 ms 640 KB
1_021.txt AC 3 ms 640 KB
1_022.txt AC 3 ms 640 KB
1_023.txt AC 3 ms 640 KB
1_024.txt AC 3 ms 640 KB
1_025.txt AC 3 ms 640 KB
1_026.txt AC 3 ms 640 KB
1_027.txt AC 3 ms 640 KB
1_028.txt AC 3 ms 640 KB
1_029.txt AC 3 ms 640 KB
1_030.txt AC 3 ms 640 KB
1_031.txt AC 3 ms 640 KB
1_032.txt AC 3 ms 640 KB
1_033.txt AC 3 ms 640 KB
1_034.txt AC 3 ms 640 KB
1_035.txt AC 3 ms 640 KB
1_036.txt AC 3 ms 640 KB
1_037.txt AC 3 ms 640 KB
1_038.txt AC 3 ms 640 KB
1_039.txt AC 3 ms 640 KB
1_040.txt AC 3 ms 640 KB
1_041.txt AC 3 ms 640 KB
1_042.txt AC 3 ms 640 KB
1_043.txt AC 3 ms 640 KB
1_044.txt AC 3 ms 640 KB
1_045.txt AC 3 ms 640 KB
1_046.txt AC 3 ms 640 KB
1_047.txt AC 3 ms 640 KB
1_048.txt AC 3 ms 640 KB
1_049.txt AC 3 ms 640 KB
1_050.txt AC 3 ms 640 KB
1_051.txt AC 3 ms 640 KB
1_052.txt AC 3 ms 640 KB
1_053.txt AC 3 ms 640 KB
1_054.txt AC 3 ms 640 KB
1_055.txt AC 3 ms 640 KB
1_056.txt AC 3 ms 640 KB
1_057.txt AC 3 ms 640 KB
1_058.txt AC 3 ms 640 KB
1_059.txt AC 3 ms 640 KB
1_060.txt AC 3 ms 640 KB
1_061.txt AC 3 ms 640 KB
1_062.txt AC 3 ms 640 KB
1_063.txt AC 3 ms 640 KB