제출 #1122441

#제출 시각아이디문제언어결과실행 시간메모리
1122441dwuyPaths (BOI18_paths)C++20
100 / 100
933 ms26780 KiB
/** - dwuy -       />  フ       |  _  _|       /`ミ _x ノ      /      |     /  ヽ   ?  / ̄|   | | |  | ( ̄ヽ__ヽ_)_)  \二つ **/ #include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) (int)((s).size()) #define MASK(k)(1LL<<(k)) #define TASK "test" #define int long long using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; const int MX = 300005; int n, m, k, ans = 0; int a[MX]; pii edges[MX]; vector<int> G[MX]; bitset<MX> vist = 0; bool ok[10][10]; int f[MX]; vector<int> ttt; void dfs(int u, vector<int> &topo){ if(vist[u]) return; vist[u] = 1; for(int v: G[u]) if(ok[a[u]][a[v]]) dfs(v, topo); topo.push_back(u); } int calc(int p){ vector<int> topo; vist = 0; int res = 0; memset(f, 0, sizeof f); for(int i=1; i<=n; i++) if(ok[0][a[i]]){ f[i] = 1; dfs(i, topo); } reverse(topo.begin(), topo.end()); for(int u: topo){ for(int v : G[u]) if(ok[a[u]][a[v]]){ f[v] += f[u]; } if(a[u] == p) res += f[u]; } return res; } void solve(int mask, int p){ ttt.push_back(p); ans += calc(p); for(int i=1; i<=k; i++) if(!(mask&MASK(i))){ ok[p][i] = 1; solve(mask^MASK(i), i); ok[p][i] = 0; } ttt.pop_back(); } int32_t main(){ fastIO; //file(TASK); cin >> n >> m >> k; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=m; i++){ int u, v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } solve(0, 0); cout << ans - n; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...