Submission #877135

#TimeUsernameProblemLanguageResultExecution timeMemory
877135MasterTasterPaths (BOI18_paths)C++14
70 / 100
260 ms25948 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define xx first #define yy second #define pb push_back #define MAXN 300010 #define MAXK 6 using namespace std; int n, m, k, a[MAXN]; ll cnt[MAXN][MAXK], ress; vector<pii> grane; int main() { cin>>n>>m>>k; for (int i=1; i<=n; i++) cin>>a[i]; for (int i=0; i<m; i++) { int u, v; cin>>u>>v; grane.pb({u, v}); cnt[u][a[v]]++; cnt[v][a[u]]++; } for (auto par:grane) { int u=par.xx, v=par.yy; if (a[u]==a[v]) continue; ress+=2; vector<int> boje; for (int i=1; i<=4; i++) if (a[u]!=i && a[v]!=i) boje.pb(i); int c1, c2; c1=boje[0]; c2=boje[1]; ress+=2*((cnt[u][c1]*cnt[v][c2])+(cnt[u][c2]*cnt[v][c1]))+cnt[u][c1]+cnt[u][c2]+cnt[v][c1]+cnt[v][c2]; //cout<<u<<" "<<v<<" "<<ress<<endl; } cout<<ress; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...