답안 #1091577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091577 2024-09-21T11:50:10 Z gyg Paths (BOI18_paths) C++17
100 / 100
490 ms 30232 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
#define vct vector
const int MX_N = 3e5 + 5, MX_K = 5 + 5;

int n, m, k;
arr<int, MX_N> cl;
arr<vct<int>, MX_N> adj;

vct<int> ord;
set<vct<int>> ords;
void bcktr(int i = 1) {
    if (i == k + 1) {
        if (ord.size() <= 1) return;
        ords.insert(ord);
        return;
    }

    bcktr(i + 1);
    for (int j = 1; j <= k; j++) {
        if (count(ord.begin(), ord.end(), j)) continue;
        ord.push_back(j);
        bcktr(i + 1);
        ord.pop_back();
    }
}
arr<vct<int>, MX_K> cl_nds;
void prcmp() {
    bcktr();
    // for (vct<int> x : ords) {
    //     for (int y : x) cout << y << " ";
    //     cout << endl;
    // }
    for (int u = 1; u <= n; u++) cl_nds[cl[u]].push_back(u);
}

arr<int, MX_N> dp;
int cmp() {
    int ans = 0;
    for (vct<int> x : ords) {
        fill(dp.begin(), dp.end(), 0);
        int nw_ans = 0;

        for (int i = 0; i < x.size(); i++) {
            for (int u : cl_nds[x[i]]) {
                if (i == 0) { dp[u] = 1; continue; }
                for (int v : adj[u])
                    if (cl[v] == x[i - 1]) dp[u] += dp[v];
            }
        }

        for (int u : cl_nds[x.back()]) nw_ans += dp[u];
        ans += nw_ans;

        // for (int y : x) cout << y << " ";
        // cout << ": " << nw_ans << endl;
    }
    return ans;
}

signed main() {
    // freopen("pth.in", "r", stdin);
    cin >> n >> m >> k;
    for (int u = 1; u <= n; u++) cin >> cl[u];
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v), adj[v].push_back(u);
    }

    prcmp();
    int ans = cmp();
    cout << ans << endl;

}

Compilation message

paths.cpp: In function 'long long int cmp()':
paths.cpp:46:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i = 0; i < x.size(); i++) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9820 KB Output is correct
2 Correct 7 ms 9820 KB Output is correct
3 Correct 4 ms 9844 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 7 ms 9820 KB Output is correct
7 Correct 7 ms 9820 KB Output is correct
8 Correct 8 ms 9820 KB Output is correct
9 Correct 7 ms 9816 KB Output is correct
10 Correct 5 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 19916 KB Output is correct
2 Correct 89 ms 19028 KB Output is correct
3 Correct 265 ms 29428 KB Output is correct
4 Correct 125 ms 21844 KB Output is correct
5 Correct 129 ms 19688 KB Output is correct
6 Correct 193 ms 27276 KB Output is correct
7 Correct 266 ms 29712 KB Output is correct
8 Correct 264 ms 30232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9820 KB Output is correct
2 Correct 7 ms 9820 KB Output is correct
3 Correct 4 ms 9844 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 7 ms 9820 KB Output is correct
7 Correct 7 ms 9820 KB Output is correct
8 Correct 8 ms 9820 KB Output is correct
9 Correct 7 ms 9816 KB Output is correct
10 Correct 5 ms 9816 KB Output is correct
11 Correct 107 ms 19916 KB Output is correct
12 Correct 89 ms 19028 KB Output is correct
13 Correct 265 ms 29428 KB Output is correct
14 Correct 125 ms 21844 KB Output is correct
15 Correct 129 ms 19688 KB Output is correct
16 Correct 193 ms 27276 KB Output is correct
17 Correct 266 ms 29712 KB Output is correct
18 Correct 264 ms 30232 KB Output is correct
19 Correct 116 ms 19796 KB Output is correct
20 Correct 94 ms 19048 KB Output is correct
21 Correct 318 ms 29456 KB Output is correct
22 Correct 125 ms 21788 KB Output is correct
23 Correct 125 ms 19548 KB Output is correct
24 Correct 200 ms 27460 KB Output is correct
25 Correct 241 ms 29708 KB Output is correct
26 Correct 240 ms 30108 KB Output is correct
27 Correct 137 ms 19028 KB Output is correct
28 Correct 167 ms 21324 KB Output is correct
29 Correct 438 ms 29740 KB Output is correct
30 Correct 303 ms 25792 KB Output is correct
31 Correct 308 ms 25544 KB Output is correct
32 Correct 490 ms 29520 KB Output is correct
33 Correct 8 ms 9820 KB Output is correct
34 Correct 8 ms 9856 KB Output is correct
35 Correct 5 ms 9820 KB Output is correct
36 Correct 5 ms 9820 KB Output is correct
37 Correct 3 ms 7260 KB Output is correct
38 Correct 7 ms 9796 KB Output is correct
39 Correct 7 ms 9820 KB Output is correct
40 Correct 8 ms 9820 KB Output is correct
41 Correct 7 ms 9820 KB Output is correct
42 Correct 6 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 9816 KB Output is correct
2 Correct 139 ms 12704 KB Output is correct
3 Correct 33 ms 12624 KB Output is correct
4 Correct 74 ms 16428 KB Output is correct
5 Correct 59 ms 17348 KB Output is correct
6 Correct 479 ms 16352 KB Output is correct
7 Correct 51 ms 12744 KB Output is correct
8 Correct 139 ms 16248 KB Output is correct
9 Correct 84 ms 17092 KB Output is correct
10 Correct 89 ms 17220 KB Output is correct
11 Correct 290 ms 14516 KB Output is correct
12 Correct 204 ms 15680 KB Output is correct
13 Correct 288 ms 15168 KB Output is correct
14 Correct 480 ms 16312 KB Output is correct
15 Correct 455 ms 16620 KB Output is correct
16 Correct 8 ms 9820 KB Output is correct
17 Correct 9 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9744 KB Output is correct
20 Correct 3 ms 7260 KB Output is correct
21 Correct 7 ms 9820 KB Output is correct
22 Correct 7 ms 9856 KB Output is correct
23 Correct 7 ms 9820 KB Output is correct
24 Correct 7 ms 9620 KB Output is correct
25 Correct 4 ms 9820 KB Output is correct