제출 #1247682

#제출 시각아이디문제언어결과실행 시간메모리
1247682nvc2k8Paths (BOI18_paths)C++20
100 / 100
221 ms92788 KiB
#include <bits/stdc++.h>
#define TASK "kasjdkasd"
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define all(C) C.begin(), C.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INT_LIM = 2147483647;
const ll LL_LIM = 9223372036854775807;
template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;}
template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;}
///------------------------------------------///
//const int MOD = 1e9+7;
void add(ll &x, const ll &y)
{
    x+=y;
}

int n,m,k;
int a[300005];
vector<int> adj[300005];

void inp()
{
    cin >> n >> m >> k;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, m)
    {
        int u,v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
}

ll dp[300005][32];

void solve()
{
    vector<int> msk;
    FOR(i, 0, (1<<k)-1) msk.pb(i);
    sort(all(msk), [&](int x, int y)
    {
        return __builtin_popcount(x) < __builtin_popcount(y);
    });

    ll ans = 0;
    for (auto mask:msk) FOR(i, 1, n) if (BIT(mask, a[i]-1))
    {
        if (__builtin_popcount(mask)==1)
        {
            dp[i][mask] = 1;
        }
        else
        {
            for (auto v:adj[i])
            {
                add(dp[i][mask], dp[v][mask^(1<<(a[i]-1))]);
            }
            add(ans, dp[i][mask]);
        }
//        cout << i << ' ' << mask << ' ' << dp[i][mask] << endl;
    }
    cout << ans;
}

signed main()
{
    ///--------------------------///
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    if (fopen(TASK".INP","r")!=NULL)
    {
        freopen(TASK".INP","r",stdin);
        freopen(TASK".OUT","w",stdout);
    }
    ///--------------------------///

    int NTEST = 1;
    bool codeforces = 0;
    if (codeforces) cin >> NTEST;

    while (NTEST--)
    {
        inp();
        solve();
    }

    return 0;
}

///------------------------------------------///

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

paths.cpp: In function 'int main()':
paths.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(TASK".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(TASK".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...