Submission #563655

# Submission time Handle Problem Language Result Execution time Memory
563655 2022-05-17T21:03:47 Z colossal_pepe Paths (BOI18_paths) C++17
23 / 100
169 ms 312 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n, m, x, c[105], factorial[5] = {1, 1, 2, 6, 24};
bool adj[105][105];

int validPaths(vector<int> path) {
    int sz = path.size();
    for (int i = 0; i < sz; i++) {
        for (int j = i + 1; j < sz; j++) {
            if (c[path[i]] == c[path[j]]) return 0;
        }
    }
    int ans = 0;
    for (int i = 0; i < factorial[sz]; i++) {
        bool connected = 1;
        for (int j = 1; j < sz; j++) {
            connected &= adj[path[j - 1]][path[j]];
        }
        ans += connected;
        next_permutation(path.begin(), path.end());
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    while (m--) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u][v] = adj[v][u] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (x >= 2) {
            for (int j = i + 1; j < n; j++) {
                ans += validPaths({i, j});
                if (x >= 3) {
                    for (int k = j + 1; k < n; k++) {
                        ans += validPaths({i, j, k});
                        if (x >= 4) {
                            for (int l = k + 1; l < n; l++) {
                                ans += validPaths({i, j, k, l});
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 169 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 164 ms 312 KB Output is correct
7 Correct 15 ms 212 KB Output is correct
8 Correct 164 ms 308 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 169 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 164 ms 312 KB Output is correct
7 Correct 15 ms 212 KB Output is correct
8 Correct 164 ms 308 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -