Submission #1165224

#TimeUsernameProblemLanguageResultExecution timeMemory
1165224dzhoz0Paths (BOI18_paths)C++20
53 / 100
107 ms31444 KiB
/*
    ghmt the cutie :3
          UwU
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>

const int MOD = 1'000'000'000;

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    if (!name.empty())
    {
        freopen((name + ".INP").c_str(), "r", stdin);
        freopen((name + ".OUT").c_str(), "w", stdout);
    }
#endif
}

const int MAXN = 1e5;
int dp[1 << 5][MAXN + 1];
int color[MAXN + 1];
vi g[MAXN + 1];
void solve()
{
    int n, m; cin >> n >> m;
    int k; cin >> k;
    for(int i = 1; i <= n; i++) {
        cin >> color[i]; color[i]--;
        dp[1 << color[i]][i] = 1;
    }
    while(m--) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
 
    for(int b = 0; b < (1 << 5); b++) {
        for(int u = 1; u <= n; u++) {
            if(b & (1 << color[u])) continue;
            for(int v : g[u]) {
                if(!(b & (1 << color[v]))) continue;
                dp[b | (1 << color[u])][u] += dp[b][v];
            }
        } 
    }
    int res = 0;
    for(int i = 1; i <= n; i++) {
        for(int b = 0; b < (1 << 5); b++) {
            if(__popcount(b) > 1) res += dp[b][i];
        }
    }
    cout << res << '\n';
}

signed main()
{
    setIO();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

Compilation message (stderr)

paths.cpp: In function 'void setIO(std::string)':
paths.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name + ".OUT").c_str(), "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...