Submission #598470

#TimeUsernameProblemLanguageResultExecution timeMemory
598470uroskPaths (BOI18_paths)C++14
20 / 100
312 ms39248 KiB
#define here cerr<<"===========================================\n" #include <bits/stdc++.h> #define ld double #define ll long long #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) (ll)(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; #define maxn 300005 #define maxk 6 ll n,m,k; ll ans = 0; vector<ll> g[maxn]; ll a[maxn]; ll dp[maxn][maxk][maxk]; ll cnt[maxn][maxk]; void kraj(){ cout<<ans<<endl; exit(0); } int main(){ daj_mi_malo_vremena cin >> n >> m >> k; for(ll i = 1;i<=n;i++) cin >> a[i]; for(ll i = 1;i<=m;i++){ ll x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } if(k==1) kraj(); ll cur = 0; for(ll i = 1;i<=n;i++){ for(ll j : g[i]){ if(a[i]==a[j]) continue; cnt[i][a[j]]++; cur++; } } ans+=cur; if(k==2) kraj(); cur = 0; for(ll i = 1;i<=n;i++){ vector<ll> v(k+1); for(ll j : g[i]){ v[a[j]]++; } ll coli = a[i]; for(ll e = 1;e<=k;e++){ for(ll r = e+1;r<=k;r++){ if(e==coli||r==coli) continue; cur+=v[e]*v[r]; } } } ans+=2*cur; if(k==3) kraj(); for(ll i = 1;i<=n;i++){ for(ll j : g[i]){ ll coli = a[i]; ll colj = a[j]; for(ll e = 1;e<=k;e++){ dp[i][colj][e] += cnt[j][e]; if(e==coli) dp[i][colj][e]--; } } } return 0; } /* 4 3 3 1 2 1 3 1 2 2 3 4 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...