Submission #863716

# Submission time Handle Problem Language Result Execution time Memory
863716 2023-10-20T18:04:19 Z alittlemiddle Paths (BOI18_paths) C++14
53 / 100
98 ms 163060 KB
#include <bits/stdc++.h>
#define task
using namespace std;
const int maxn=1e5+4;
const int maxk=6;
const int BASE=33;
int n,m,k,u,v;
vector <int> mask[maxk][maxk];
vector <int> adj[maxn];
long long dp[maxn][maxk][BASE];
long long ans=0;
int col[maxn];
void input()
{
    cin>>n>>m>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>col[i];
    }
    for (int i=1;i<=m;i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i=0;i<(1<<k);i++)
    {
        int x=0,y=i;
        while (y>0) {x+=y%2; y/=2;}
        for (int j=1;j<=k;j++)
        if (i&(1<<(j-1))) mask[x][j].push_back(i);
    }
}
void solve()
{
    for (int i=1;i<=n;i++)
    {
        dp[i][1][1<<(col[i]-1)]=1;
    }
    for (int i=2;i<=k;i++)
    {
        for (int j=1;j<=n;j++)
        {

            for (int x:mask[i][col[j]])
            {
                for (int y:adj[j])
                dp[j][i][x]+=dp[y][i-1][x^(1<<(col[j]-1))];
                ans+=dp[j][i][x];
                //cout<<j<<" "<<i<<" "<<x<<" "<<dp[j][i][x]<<"\n";
            }
        }
    }
    cout<<ans;

}
signed main()
{
    if (fopen(task".INP","r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    input();
    solve();


}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 6068 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 18216 KB Output is correct
2 Correct 34 ms 11804 KB Output is correct
3 Runtime error 20 ms 13144 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 6068 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 44 ms 18216 KB Output is correct
12 Correct 34 ms 11804 KB Output is correct
13 Runtime error 20 ms 13144 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5976 KB Output is correct
2 Correct 15 ms 7768 KB Output is correct
3 Correct 12 ms 7772 KB Output is correct
4 Correct 53 ms 162308 KB Output is correct
5 Correct 44 ms 162864 KB Output is correct
6 Correct 92 ms 162308 KB Output is correct
7 Correct 13 ms 7888 KB Output is correct
8 Correct 68 ms 162308 KB Output is correct
9 Correct 59 ms 163024 KB Output is correct
10 Correct 69 ms 163060 KB Output is correct
11 Correct 61 ms 85196 KB Output is correct
12 Correct 62 ms 125140 KB Output is correct
13 Correct 57 ms 85212 KB Output is correct
14 Correct 94 ms 162268 KB Output is correct
15 Correct 98 ms 162384 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 1 ms 6164 KB Output is correct
18 Correct 1 ms 5980 KB Output is correct
19 Correct 1 ms 5980 KB Output is correct
20 Correct 1 ms 5980 KB Output is correct
21 Correct 1 ms 5976 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 1 ms 5976 KB Output is correct
24 Correct 1 ms 5980 KB Output is correct
25 Correct 2 ms 5980 KB Output is correct