Submission #598480

#TimeUsernameProblemLanguageResultExecution timeMemory
598480uroskPaths (BOI18_paths)C++14
70 / 100
301 ms43980 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]; vector<pll> edg; 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; edg.pb({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; cerr<<"k = 3: "<<ans<<endl; if(k==3) kraj(); cur = 0; for(pll p : edg){ ll x = p.fi; ll y = p.sc; ll colx = a[x]; ll coly = a[y]; if(colx==coly) continue; for(ll e = 1;e<=k;e++){ if(e==colx||e==coly) continue; for(ll r = e+1;r<=k;r++){ if(r==colx||r==coly) continue; cur+=cnt[x][e]*cnt[y][r]; cur+=cnt[x][r]*cnt[y][e]; } } } cur*=2; ans+=cur; if(k==4) 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 9 11 4 1 2 3 4 1 2 1 2 2 1 2 1 3 2 3 2 4 3 6 6 2 6 5 4 3 4 5 7 8 9 8 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...