Submission #852395

# Submission time Handle Problem Language Result Execution time Memory
852395 2023-09-21T18:15:24 Z Benmath Paths (BOI18_paths) C++14
53 / 100
1988 ms 1022444 KB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
long long int dp[100005][6][6][6][6];
int boja[100005];
int n;
int m;
int k;
vector<int>adjl[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++){
        cin >> boja[i];
    }
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        adjl[x].push_back(y);
        adjl[y].push_back(x);
    }
    long long int ans = 0;
    for (int i = k; i >= 0; i--){
        for (int j = k; j >= 0; j--){
            for (int t = k; t >= 0; t--){
                for (int t1 = k; t1 >= 0; t1--){
                    int check1 = 0;
                    if (i == 0){
                        if(j==0 and t==0 and t1==0){
                        
                        }else{
                            check1++;
                        }
                    }else{
                        if(j==0){
                            if(t==0 and t1==0){
                                
                            }else{
                                check1++;
                            }
                        }else{
                            if(t==0){
                                if(t1!=0){
                                    check1++;
                                }
                            }
                        }
                    }
                    if (i == j and i > 0){
                        check1 ++;
                    } 
                    if (j == t and j > 0){
                        check1 ++;
                    }
                    if (i == t and i > 0){
                        check1 ++;
                    }
                    if (i == t1 and i > 0){
                        check1 ++;
                    }
                    if(j==t1 and j>0){
                        check1++;
                    }
                    if(t==t1 and t>0){
                        check1++;
                    }
                    if(check1==0){
                    for (int node = 1; node <= n; node++){
                       if (i == 0){
                         if (j == 0 and t == 0 and t1 == 0){
                            for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
                                int x = boja[adjl[node][susjed]];
                                if(x != boja[node] and x != i and x != j and x != t and x != t1){
                                    dp[node][i][j][t][t1] += dp[adjl[node][susjed]][boja[node]][0][0][0];
                                }
                            }
                        }
                    }else{
                        if (j == 0){
                            if (t == 0 and t1 == 0){
                                 for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
                                    int x = boja[adjl[node][susjed]];
                                    if(x != boja[node] and x != i and x != j and x != t and x!=t1){
                                         dp[node][i][j][t][t1] += dp[adjl[node][susjed]][i][boja[node]][0][0];
                                    }
                                  }
                            }
                        }else{
                            if (t == 0){
                                if(t1==0){
                                for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
                                    int x = boja[adjl[node][susjed]];
                                    if(x != boja[node] and x != i and x != j and x != t and x!=t1){
                                         dp[node][i][j][t][t1] += dp[adjl[node][susjed]][i][j][boja[node]][0];
                                    }
                               }
                                }
                            }else{
                              for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
                                    int x = boja[adjl[node][susjed]];
                                    if(x != boja[node] and x != i and x != j and x != t and x!=t1){
                                         dp[node][i][j][t][t1] += dp[adjl[node][susjed]][i][j][t][boja[node]];
                                    }
                               }
                            }
                        }
                    }
             
                    
                    if(boja[node] != i and boja[node] != j and boja[node] != t and  boja[node] != t1){
                        dp[node][i][j][t][t1] += 1;
                    }
                    if(i == 0 and j == 0 and t == 0 and t1==0){
                        ans = ans + dp[node][i][j][t][t1];
                        ans --;
                    }
                    //cout << dp[node][i][j][t]<<" "<<i<<" "<<j<<" "<<t<<" "<<node<<" "<<boja[node]<<endl;
                }
                    }
            }
        }
    }
    }
    cout << ans << endl;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:81:57: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                             for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~
paths.cpp:91:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |                                  for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
      |                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~
paths.cpp:101:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |                                 for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
      |                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~
paths.cpp:109:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                               for (int susjed = 0; susjed < adjl[node].size(); susjed ++){
      |                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 55120 KB Output is correct
2 Correct 97 ms 14420 KB Output is correct
3 Runtime error 39 ms 9304 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 136 ms 55120 KB Output is correct
12 Correct 97 ms 14420 KB Output is correct
13 Runtime error 39 ms 9304 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 335 ms 9212 KB Output is correct
3 Correct 33 ms 8784 KB Output is correct
4 Correct 522 ms 943776 KB Output is correct
5 Correct 305 ms 962756 KB Output is correct
6 Correct 1983 ms 1020440 KB Output is correct
7 Correct 109 ms 9728 KB Output is correct
8 Correct 947 ms 1018708 KB Output is correct
9 Correct 505 ms 1022444 KB Output is correct
10 Correct 412 ms 1022444 KB Output is correct
11 Correct 1000 ms 513284 KB Output is correct
12 Correct 946 ms 768120 KB Output is correct
13 Correct 972 ms 513844 KB Output is correct
14 Correct 1932 ms 1021948 KB Output is correct
15 Correct 1988 ms 1021816 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 4960 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 2 ms 4696 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 1 ms 4696 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4696 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct