답안 #1090322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090322 2024-09-18T08:42:04 Z andrei_iorgulescu Paths (BOI18_paths) C++14
100 / 100
750 ms 41556 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, m, k;
int a[300005];
vector<int> g[300005];
int ans;
bool iau[10];
int dp[300005][7];

void solve(vector<int> mele)
{
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++)
        if (a[i] == mele[0])
            dp[i][1] = 1;
    for (int j = 2; j <= mele.size(); j++)
    {
        for (int i = 1; i <= n; i++)
            if (a[i] == mele[j - 1])
                for (auto vecin : g[i])
                    dp[i][j] += dp[vecin][j - 1];
    }
    for (int i = 1; i <= n; i++)
        ans += dp[i][mele.size()];
}

void bkt(int pos)
{
    if (pos == k + 1)
    {
        vector<int> mele;
        for (int i = 1; i <= k; i++)
            if (iau[i])
                mele.push_back(i);
        if (mele.empty())
            return;
        do
        {
            solve(mele);
        }while (next_permutation(mele.begin(), mele.end()));
    }
    else
    {
        iau[pos] = false;
        bkt(pos + 1);
        iau[pos] = true;
        bkt(pos + 1);
    }
}

signed main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    bkt(1);
    cout << ans - n;
    return 0;
}

Compilation message

paths.cpp: In function 'void solve(std::vector<long long int>)':
paths.cpp:20:23: 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]
   20 |     for (int j = 2; j <= mele.size(); j++)
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 23900 KB Output is correct
2 Correct 31 ms 23736 KB Output is correct
3 Correct 14 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 7 ms 25180 KB Output is correct
6 Correct 32 ms 23900 KB Output is correct
7 Correct 32 ms 23900 KB Output is correct
8 Correct 30 ms 23896 KB Output is correct
9 Correct 32 ms 23896 KB Output is correct
10 Correct 15 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 33864 KB Output is correct
2 Correct 98 ms 34368 KB Output is correct
3 Correct 290 ms 41044 KB Output is correct
4 Correct 133 ms 35612 KB Output is correct
5 Correct 125 ms 35572 KB Output is correct
6 Correct 223 ms 38332 KB Output is correct
7 Correct 265 ms 41232 KB Output is correct
8 Correct 257 ms 41556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 23900 KB Output is correct
2 Correct 31 ms 23736 KB Output is correct
3 Correct 14 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 7 ms 25180 KB Output is correct
6 Correct 32 ms 23900 KB Output is correct
7 Correct 32 ms 23900 KB Output is correct
8 Correct 30 ms 23896 KB Output is correct
9 Correct 32 ms 23896 KB Output is correct
10 Correct 15 ms 23900 KB Output is correct
11 Correct 115 ms 33864 KB Output is correct
12 Correct 98 ms 34368 KB Output is correct
13 Correct 290 ms 41044 KB Output is correct
14 Correct 133 ms 35612 KB Output is correct
15 Correct 125 ms 35572 KB Output is correct
16 Correct 223 ms 38332 KB Output is correct
17 Correct 265 ms 41232 KB Output is correct
18 Correct 257 ms 41556 KB Output is correct
19 Correct 117 ms 33876 KB Output is correct
20 Correct 87 ms 33096 KB Output is correct
21 Correct 271 ms 41232 KB Output is correct
22 Correct 123 ms 36524 KB Output is correct
23 Correct 119 ms 36604 KB Output is correct
24 Correct 216 ms 38184 KB Output is correct
25 Correct 257 ms 41040 KB Output is correct
26 Correct 310 ms 41552 KB Output is correct
27 Correct 124 ms 33044 KB Output is correct
28 Correct 171 ms 35172 KB Output is correct
29 Correct 750 ms 41156 KB Output is correct
30 Correct 421 ms 38000 KB Output is correct
31 Correct 399 ms 37832 KB Output is correct
32 Correct 704 ms 41256 KB Output is correct
33 Correct 30 ms 25180 KB Output is correct
34 Correct 28 ms 23896 KB Output is correct
35 Correct 12 ms 23940 KB Output is correct
36 Correct 8 ms 23900 KB Output is correct
37 Correct 7 ms 25180 KB Output is correct
38 Correct 30 ms 23912 KB Output is correct
39 Correct 30 ms 25176 KB Output is correct
40 Correct 29 ms 23900 KB Output is correct
41 Correct 28 ms 23900 KB Output is correct
42 Correct 12 ms 25180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 23924 KB Output is correct
2 Correct 182 ms 26860 KB Output is correct
3 Correct 36 ms 26708 KB Output is correct
4 Correct 79 ms 29324 KB Output is correct
5 Correct 78 ms 29832 KB Output is correct
6 Correct 727 ms 29936 KB Output is correct
7 Correct 65 ms 26712 KB Output is correct
8 Correct 181 ms 29316 KB Output is correct
9 Correct 159 ms 29896 KB Output is correct
10 Correct 170 ms 29636 KB Output is correct
11 Correct 483 ms 28908 KB Output is correct
12 Correct 493 ms 28736 KB Output is correct
13 Correct 419 ms 28176 KB Output is correct
14 Correct 745 ms 29524 KB Output is correct
15 Correct 733 ms 29636 KB Output is correct
16 Correct 28 ms 23896 KB Output is correct
17 Correct 29 ms 23900 KB Output is correct
18 Correct 12 ms 23896 KB Output is correct
19 Correct 8 ms 25180 KB Output is correct
20 Correct 7 ms 23704 KB Output is correct
21 Correct 29 ms 25180 KB Output is correct
22 Correct 29 ms 23896 KB Output is correct
23 Correct 28 ms 23916 KB Output is correct
24 Correct 32 ms 23900 KB Output is correct
25 Correct 13 ms 23900 KB Output is correct