結果

問題 No.1111 コード進行
ユーザー trineutron
提出日時 2020-02-10 16:35:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 848 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 205,152 KB
最終ジャッジ日時 2025-01-08 23:25:14
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35 TLE * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int dfs(int n, int k, int present, const set<int> &chord, const map<pair<int, int>, int> &seq) {
    if (k < 0) return 0;
    if (n == 0 && k == 0) return 1;
    if (n == 0) return 0;
    int ans = 0;
    for (auto c : chord) {
        if (seq.find(make_pair(present, c)) == seq.end()) continue;
        ans += dfs(n - 1, k - seq.at(make_pair(present, c)), c, chord, seq);
    }
    return ans;
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    set<int> chord;
    map<pair<int, int>, int> seq;
    for (int i = 0; i < m; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        chord.insert(p);
        chord.insert(q);
        seq[make_pair(p, q)] = c;
    }
    int ans = 0;
    for (auto c : chord) {
        ans += dfs(n - 1, k, c, chord, seq);
    }
    cout << ans << endl;
}
0