답안 #96540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96540 2019-02-10T08:24:44 Z Kastanda Paths (BOI18_paths) C++11
100 / 100
795 ms 32664 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 300005;
int n, m, k, C[N];
long long tot, dp[N];
vector < int > P, A[N], Adj[N];
inline void Solve()
{
    if ((int)P.size() <= 1)
        return ;
    vector < int > V = P;
    do
    {
        memset(dp, 0, sizeof(dp));
        for (int v : A[V[0]])
            dp[v] = 1;
        for (int i = 1; i < (int)V.size(); i++)
            for (int v : A[V[i]])
                for (int u : Adj[v])
                    if (C[u] == V[i - 1])
                        dp[v] += dp[u];
        for (int v : A[V.back()])
            tot += dp[v];
    } while (next_permutation(V.begin(), V.end()));
}
void Generate(int a)
{
    if ((int)P.size() == k || a > k)
        return ;
    P.pb(a); Solve();
    Generate(a + 1);
    P.pop_back();
    Generate(a + 1);
}
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &C[i]), A[C[i]].pb(i);
    for (int i = 1; i <= m; i++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[v].pb(u);
        Adj[u].pb(v);
    }
    Generate(1);
    return !printf("%lld\n", tot);
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:40:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &C[i]), A[C[i]].pb(i);
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
paths.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 16760 KB Output is correct
2 Correct 25 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 14 ms 16760 KB Output is correct
5 Correct 13 ms 14456 KB Output is correct
6 Correct 20 ms 16760 KB Output is correct
7 Correct 20 ms 16760 KB Output is correct
8 Correct 21 ms 16888 KB Output is correct
9 Correct 20 ms 16760 KB Output is correct
10 Correct 18 ms 16760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 23280 KB Output is correct
2 Correct 100 ms 22520 KB Output is correct
3 Correct 434 ms 32008 KB Output is correct
4 Correct 144 ms 24824 KB Output is correct
5 Correct 126 ms 22392 KB Output is correct
6 Correct 257 ms 29548 KB Output is correct
7 Correct 363 ms 31944 KB Output is correct
8 Correct 391 ms 32664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 16760 KB Output is correct
2 Correct 25 ms 16760 KB Output is correct
3 Correct 16 ms 16760 KB Output is correct
4 Correct 14 ms 16760 KB Output is correct
5 Correct 13 ms 14456 KB Output is correct
6 Correct 20 ms 16760 KB Output is correct
7 Correct 20 ms 16760 KB Output is correct
8 Correct 21 ms 16888 KB Output is correct
9 Correct 20 ms 16760 KB Output is correct
10 Correct 18 ms 16760 KB Output is correct
11 Correct 132 ms 23280 KB Output is correct
12 Correct 100 ms 22520 KB Output is correct
13 Correct 434 ms 32008 KB Output is correct
14 Correct 144 ms 24824 KB Output is correct
15 Correct 126 ms 22392 KB Output is correct
16 Correct 257 ms 29548 KB Output is correct
17 Correct 363 ms 31944 KB Output is correct
18 Correct 391 ms 32664 KB Output is correct
19 Correct 114 ms 23220 KB Output is correct
20 Correct 94 ms 22492 KB Output is correct
21 Correct 356 ms 31928 KB Output is correct
22 Correct 142 ms 24808 KB Output is correct
23 Correct 157 ms 22392 KB Output is correct
24 Correct 261 ms 29664 KB Output is correct
25 Correct 324 ms 31976 KB Output is correct
26 Correct 326 ms 32632 KB Output is correct
27 Correct 175 ms 22520 KB Output is correct
28 Correct 207 ms 24184 KB Output is correct
29 Correct 795 ms 32032 KB Output is correct
30 Correct 459 ms 27952 KB Output is correct
31 Correct 446 ms 28080 KB Output is correct
32 Correct 709 ms 32128 KB Output is correct
33 Correct 26 ms 16760 KB Output is correct
34 Correct 22 ms 16760 KB Output is correct
35 Correct 15 ms 16760 KB Output is correct
36 Correct 14 ms 16760 KB Output is correct
37 Correct 12 ms 14456 KB Output is correct
38 Correct 23 ms 16760 KB Output is correct
39 Correct 21 ms 16760 KB Output is correct
40 Correct 21 ms 16760 KB Output is correct
41 Correct 22 ms 16760 KB Output is correct
42 Correct 16 ms 16760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 16760 KB Output is correct
2 Correct 202 ms 18728 KB Output is correct
3 Correct 44 ms 18644 KB Output is correct
4 Correct 102 ms 21836 KB Output is correct
5 Correct 70 ms 22396 KB Output is correct
6 Correct 700 ms 21880 KB Output is correct
7 Correct 67 ms 18552 KB Output is correct
8 Correct 187 ms 21752 KB Output is correct
9 Correct 113 ms 22548 KB Output is correct
10 Correct 196 ms 22384 KB Output is correct
11 Correct 431 ms 20216 KB Output is correct
12 Correct 322 ms 21616 KB Output is correct
13 Correct 417 ms 20336 KB Output is correct
14 Correct 719 ms 21752 KB Output is correct
15 Correct 688 ms 22008 KB Output is correct
16 Correct 25 ms 16760 KB Output is correct
17 Correct 22 ms 16760 KB Output is correct
18 Correct 18 ms 16760 KB Output is correct
19 Correct 15 ms 16760 KB Output is correct
20 Correct 13 ms 14456 KB Output is correct
21 Correct 23 ms 16760 KB Output is correct
22 Correct 24 ms 16760 KB Output is correct
23 Correct 24 ms 16760 KB Output is correct
24 Correct 23 ms 16760 KB Output is correct
25 Correct 17 ms 16732 KB Output is correct