이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define all(v) v.begin(), v.end()
#define bpc(x) __builtin_popcount(x)
#define endl "\n"
using namespace std;
const int sz = 3e5 + 5; /// mind the sz
const ll inf = 1e18;
// using namespace __gnu_pbds;
// tree <ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> rbt;
ll n, m, k, dp[sz][33], a[sz];
vl e[sz];
ll recursiondpbetch(ll node, ll mask){
mask |= (1 << a[node]);
if(dp[node][mask] != -1){return dp[node][mask];}
ll ans = 0;
if(bpc(mask) > 1){ans++;}
for(auto edge: e[node]){
if(!(mask & (1 << a[edge]))){
ans += recursiondpbetch(edge, mask);
}
}
return dp[node][mask] = ans;
}
void solve(){
ll i, j, u, v, res = 0;
cin >> n >> m >> k;
for(i = 1; i <= n; i++){
cin >> a[i];
}
for(i = 1; i <= m; i++){
cin >> u >> v;
e[u].pb(v);
e[v].pb(u);
}
memset(dp, -1, sizeof(dp));
for(i = 1; i <= n; i++){
res += recursiondpbetch(i, 0);
}
cout << res << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
paths.cpp: In function 'void solve()':
paths.cpp:36:11: warning: unused variable 'j' [-Wunused-variable]
36 | ll i, j, u, v, res = 0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |