제출 #1299460

#제출 시각아이디문제언어결과실행 시간메모리
1299460daotuankhoiPaths (BOI18_paths)C++20
53 / 100
164 ms7896 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }

const int MAXN = 2e5 + 5;
int col[MAXN];
vector<int> v[10], g[MAXN];
int id[MAXN], a[MAXN];
int n, m, k;
bool vis[MAXN];
ll ans = 0, dp[MAXN];

void backtrack(int pos) {
    if (pos == k) return;
    for (int i = 1; i <= k; i++) {
        if (vis[i]) continue;
        vis[i] = 1;
        a[pos] = i;
        if (pos == 0) {
            for (int x : v[i]) dp[x] = 1;
        } else {
            for (int x : v[i]) {
                dp[x] = 0;
                for (int y : g[x]) {
                    if (col[y] == a[pos - 1]) dp[x] += dp[y];
                }
                ans += dp[x];
            }
        }
        backtrack(pos + 1);
        vis[i] = 0;
    }
}

int main() {
    #define NAME "test"
    if (fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> col[i];
        v[col[i]].emplace_back(i);
    }
    for (int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    backtrack(0);
    cout << ans << '\n';
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

paths.cpp: In function 'int main()':
paths.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...