Submission #185212

# Submission time Handle Problem Language Result Execution time Memory
185212 2020-01-11T08:31:25 Z Ruxandra985 Paths (BOI18_paths) C++14
100 / 100
638 ms 77304 KB
#include <bits/stdc++.h>
 
using namespace std;
deque <pair <int,int> > dq;
long long dp[32][300010];
int cul[300010] , f[32][300010];
vector <int> v[300010];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , m , k , i , j , nod , vecin , conf , x, y;
    long long sol;
    fscanf (fin,"%d%d%d",&n,&m,&k);
    for (i=1;i<=n;i++){
        fscanf (fin,"%d",&cul[i]);
        cul[i]--;
        dp[(1 << cul[i])][i] = 1;
        f[(1 << cul[i])][i] = 1;
        dq.push_back(make_pair((1 << cul[i]) , i));
    }
    for (i=1;i<=m;i++){
        fscanf (fin,"%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    while (!dq.empty()){
        conf = dq.front().first;
        nod = dq.front().second;
        dq.pop_front();
        for (i=0;i<v[nod].size();i++){
            vecin = v[nod][i];
            if ((conf & ( 1 << cul[vecin])) == 0){
                dp[(conf | ( 1 << cul[vecin]))][vecin] += dp[conf][nod];
                if (!f[(conf | ( 1 << cul[vecin]))][vecin]){
                    f[(conf | ( 1 << cul[vecin]))][vecin] = 1;
                    dq.push_back(make_pair( (conf | ( 1 << cul[vecin])) , vecin ));
                }
            }
        }
    }
    sol = 0;
    for (i=0;i<32;i++)
        for (j=1;j<=n;j++)
            sol+=dp[i][j];
    fprintf (fout,"%lld",sol - n);
    return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i=0;i<v[nod].size();i++){
                  ~^~~~~~~~~~~~~~
paths.cpp:14:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d%d",&n,&m,&k);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:16:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&cul[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~~~
paths.cpp:23:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&x,&y);
         ~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7672 KB Output is correct
2 Correct 9 ms 7672 KB Output is correct
3 Correct 8 ms 7544 KB Output is correct
4 Correct 6 ms 7544 KB Output is correct
5 Correct 7 ms 7544 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7672 KB Output is correct
8 Correct 9 ms 7672 KB Output is correct
9 Correct 9 ms 7548 KB Output is correct
10 Correct 9 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 11768 KB Output is correct
2 Correct 97 ms 11256 KB Output is correct
3 Correct 498 ms 48052 KB Output is correct
4 Correct 190 ms 17016 KB Output is correct
5 Correct 176 ms 16136 KB Output is correct
6 Correct 365 ms 38688 KB Output is correct
7 Correct 480 ms 48852 KB Output is correct
8 Correct 498 ms 49560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7672 KB Output is correct
2 Correct 9 ms 7672 KB Output is correct
3 Correct 8 ms 7544 KB Output is correct
4 Correct 6 ms 7544 KB Output is correct
5 Correct 7 ms 7544 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7672 KB Output is correct
8 Correct 9 ms 7672 KB Output is correct
9 Correct 9 ms 7548 KB Output is correct
10 Correct 9 ms 7544 KB Output is correct
11 Correct 121 ms 11768 KB Output is correct
12 Correct 97 ms 11256 KB Output is correct
13 Correct 498 ms 48052 KB Output is correct
14 Correct 190 ms 17016 KB Output is correct
15 Correct 176 ms 16136 KB Output is correct
16 Correct 365 ms 38688 KB Output is correct
17 Correct 480 ms 48852 KB Output is correct
18 Correct 498 ms 49560 KB Output is correct
19 Correct 122 ms 14672 KB Output is correct
20 Correct 97 ms 13536 KB Output is correct
21 Correct 638 ms 48868 KB Output is correct
22 Correct 176 ms 16888 KB Output is correct
23 Correct 224 ms 16300 KB Output is correct
24 Correct 451 ms 38632 KB Output is correct
25 Correct 601 ms 48792 KB Output is correct
26 Correct 539 ms 49580 KB Output is correct
27 Correct 117 ms 13636 KB Output is correct
28 Correct 166 ms 16740 KB Output is correct
29 Correct 567 ms 77304 KB Output is correct
30 Correct 411 ms 48588 KB Output is correct
31 Correct 448 ms 44372 KB Output is correct
32 Correct 570 ms 77256 KB Output is correct
33 Correct 7 ms 7672 KB Output is correct
34 Correct 13 ms 7672 KB Output is correct
35 Correct 8 ms 7544 KB Output is correct
36 Correct 7 ms 7544 KB Output is correct
37 Correct 9 ms 7544 KB Output is correct
38 Correct 9 ms 7672 KB Output is correct
39 Correct 9 ms 7672 KB Output is correct
40 Correct 10 ms 7672 KB Output is correct
41 Correct 9 ms 7544 KB Output is correct
42 Correct 10 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7624 KB Output is correct
2 Correct 55 ms 8980 KB Output is correct
3 Correct 39 ms 8700 KB Output is correct
4 Correct 138 ms 19976 KB Output is correct
5 Correct 110 ms 19664 KB Output is correct
6 Correct 223 ms 48632 KB Output is correct
7 Correct 43 ms 8824 KB Output is correct
8 Correct 158 ms 29488 KB Output is correct
9 Correct 117 ms 25200 KB Output is correct
10 Correct 143 ms 23668 KB Output is correct
11 Correct 133 ms 29812 KB Output is correct
12 Correct 118 ms 22868 KB Output is correct
13 Correct 150 ms 24216 KB Output is correct
14 Correct 191 ms 48544 KB Output is correct
15 Correct 206 ms 48576 KB Output is correct
16 Correct 9 ms 7672 KB Output is correct
17 Correct 13 ms 7672 KB Output is correct
18 Correct 8 ms 7632 KB Output is correct
19 Correct 8 ms 7516 KB Output is correct
20 Correct 9 ms 7544 KB Output is correct
21 Correct 9 ms 7672 KB Output is correct
22 Correct 9 ms 7676 KB Output is correct
23 Correct 7 ms 7672 KB Output is correct
24 Correct 9 ms 7544 KB Output is correct
25 Correct 9 ms 7544 KB Output is correct