Submission #931978


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 101;
vi e[maxn];
int vis[maxn], tin[maxn], up[maxn];
int T = 0;

void dfs(int v, int p, vector<pii> &st, vector< vector<pii> > &comps) {
    vis[v] = 1;
    tin[v] = up[v] = T++;
    for (int u: e[v]) {
        if (u == p || vis[u] == 2) continue;
        st.pb(mp(v, u));
        if (vis[u] == 0) {
            dfs(u, v, st, comps);
            if (up[u] >= tin[v]) {
                vector<pii> comp;
                do {
                    comp.pb(st.back());
                    st.pop_back();
                } while (comp.back() != mp(v, u));
                comps.pb(comp);
            }
            uin(up[v], up[u]);
        } else if (vis[u] == 1) uin(up[v], tin[u]);
    }
    vis[v] = 2;
}

const i64 P = 1000000000 + 7;

i64 deg(i64 x, i64 d) {
    d %= P - 1;
    if (d < 0) d += P - 1;
    i64 y = 1;
    while (d) {
        if (d & 1) y *= x, y %= P;
        x *= x, x %= P;
        d /= 2;
    }
    return y;
}

int mu[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, m, k;
    cin >> n >> m >> k;
    forn(i, m) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        e[x].pb(y);
        e[y].pb(x);
    }

    mu[1] = 1;
    for (int i = 1; i < maxn; ++i) {
        for (int j = 2 * i; j < maxn; j += i) mu[j] -= mu[i];
    }

    i64 ans = 1;
    forn(i, n) {
        if (vis[i]) continue;
        vector<pii> st;
        vector< vector<pii> > comps;
        dfs(i, -1, st, comps);
        for (auto w: comps) {
            if (w.size() == 1) {
                ans *= k;
                ans %= P;
                continue;
            }
            set<int> s;
            for (pii p: w) s.insert(p.fi), s.insert(p.se);
            if (s.size() == w.size()) {
                int l = s.size();
                i64 t = 0;
                for (int d1 = 1; d1 <= l; ++d1) {
                    for (int d = d1; d <= l; d += d1) {
                        if (l % d) continue;
                        t += deg(d, -1) * mu[d / d1] * deg(k, d1);
                        t %= P;
                    }
                }
//                cerr << t << '\n';
                if (t < 0) t += P;
                ans *= t; ans %= P;
            } else {
                i64 t = 1;
                forn(i, w.size()) {
                    t *= k + i; t %= P;
                    t *= deg(i + 1, -1); t %= P;
                }
                ans *= t; ans %= P;
            }
        }
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Submission Info

Submission Time
Task F - Painting Graphs with AtCoDeer
User endagorion
Language C++14 (GCC 5.4.1)
Score 1300
Code Size 3869 Byte
Status AC
Exec Time 3 ms
Memory 256 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 256 KB
0_001.txt AC 3 ms 256 KB
0_002.txt AC 3 ms 256 KB
1_003.txt AC 3 ms 256 KB
1_004.txt AC 3 ms 256 KB
1_005.txt AC 3 ms 256 KB
1_006.txt AC 3 ms 256 KB
1_007.txt AC 3 ms 256 KB
1_008.txt AC 3 ms 256 KB
1_009.txt AC 3 ms 256 KB
1_010.txt AC 3 ms 256 KB
1_011.txt AC 3 ms 256 KB
1_012.txt AC 3 ms 256 KB
1_013.txt AC 3 ms 256 KB
1_014.txt AC 3 ms 256 KB
1_015.txt AC 3 ms 256 KB
1_016.txt AC 3 ms 256 KB
1_017.txt AC 3 ms 256 KB
1_018.txt AC 3 ms 256 KB
1_019.txt AC 3 ms 256 KB
1_020.txt AC 3 ms 256 KB
1_021.txt AC 3 ms 256 KB
1_022.txt AC 3 ms 256 KB
1_023.txt AC 3 ms 256 KB
1_024.txt AC 3 ms 256 KB
1_025.txt AC 3 ms 256 KB
1_026.txt AC 3 ms 256 KB
1_027.txt AC 3 ms 256 KB
1_028.txt AC 3 ms 256 KB
1_029.txt AC 3 ms 256 KB
1_030.txt AC 3 ms 256 KB
1_031.txt AC 3 ms 256 KB
1_032.txt AC 3 ms 256 KB
1_033.txt AC 3 ms 256 KB
1_034.txt AC 3 ms 256 KB
1_035.txt AC 3 ms 256 KB
1_036.txt AC 3 ms 256 KB
1_037.txt AC 3 ms 256 KB
1_038.txt AC 3 ms 256 KB
1_039.txt AC 3 ms 256 KB
1_040.txt AC 3 ms 256 KB
1_041.txt AC 3 ms 256 KB
1_042.txt AC 3 ms 256 KB
1_043.txt AC 3 ms 256 KB
1_044.txt AC 3 ms 256 KB
1_045.txt AC 3 ms 256 KB
1_046.txt AC 3 ms 256 KB
1_047.txt AC 3 ms 256 KB
1_048.txt AC 3 ms 256 KB
1_049.txt AC 3 ms 256 KB
1_050.txt AC 3 ms 256 KB
1_051.txt AC 3 ms 256 KB
1_052.txt AC 3 ms 256 KB
1_053.txt AC 3 ms 256 KB
1_054.txt AC 3 ms 256 KB
1_055.txt AC 3 ms 256 KB
1_056.txt AC 3 ms 256 KB
1_057.txt AC 3 ms 256 KB
1_058.txt AC 3 ms 256 KB
1_059.txt AC 3 ms 256 KB
1_060.txt AC 3 ms 256 KB
1_061.txt AC 3 ms 256 KB
1_062.txt AC 3 ms 256 KB
1_063.txt AC 3 ms 256 KB