結果

問題 No.329 全射
ユーザー kyunakyuna
提出日時 2019-08-19 12:24:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,929 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 71,360 KB
最終ジャッジ日時 2024-11-14 21:34:59
合計ジャッジ時間 958 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'void warshall_floyd_kai(Matrix<T>&)':
main.cpp:20:19: error: 'numeric_limits' was not declared in this scope
   20 |     const T INF = numeric_limits<T>::max();
      |                   ^~~~~~~~~~~~~~
main.cpp:20:35: error: expected primary-expression before '>' token
   20 |     const T INF = numeric_limits<T>::max();
      |                                   ^
main.cpp:20:41: error: no matching function for call to 'max()'
   20 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/algorithm:60,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
main.cpp:20:41: note:   candidate expects 2 arguments, 0 provided
   20 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
main.cpp:20:41: note:   candidate expects 3 arguments, 0 provided
   20 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/algorithm:61:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const int MOD = (int)1e9 + 7;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
void warshall_floyd_kai(Matrix<T> &g) {
    const T INF = numeric_limits<T>::max();
    for (int k = 0; k < g.size(); k++) {
        for (int i = 0; i < g.size(); i++) if (g[i][k] != INF) {
            for (int j = 0; j < g.size(); j++) if (g[k][j] != INF) {
                g[i][j] = max(g[i][j], min(g[i][k], g[k][j]));
            }
        }
    }
}

vector<vector<long long>> stirling2_table(int ma) {
    vector<vector<long long>> dp(ma + 1, vector<long long>(ma + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= ma; i++) {
        dp[i][1] = 1;
        for (int j = 2; j <= i; j++) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j] * j) % MOD;
        }
    }
    return dp;
}

int main() {
    int V, E; cin >> V >> E;
    vector<int> w(V);
    for (int &wi: w) cin >> wi;
    Matrix<int> mat(V, vector<int>(V, 0));
    for (int i = 0; i < V; i++) mat[i][i] = w[i];
    while (E--) {
        int s, t; cin >> s >> t; s--, t--;
        mat[s][t] = min(w[s], w[t]);
    }
    warshall_floyd_kai(mat);
    const int MAX = 1000;
    auto dp = stirling2_table(MAX);
    vector<long long> fact(MAX + 1, 1);
    for (int i = 2; i <= MAX; i++) fact[i] = fact[i - 1] * i % MOD;
    long long ans = 0;
    for (int i = 0; i < V; i++) for (int j = 0; j < V; j++) {
        if (mat[i][j] >= w[j]) (ans += dp[w[i]][w[j]] * fact[w[j]]) %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0