제출 #986187

#제출 시각아이디문제언어결과실행 시간메모리
986187AiperiiiPaths (BOI18_paths)C++14
23 / 100
3052 ms1048576 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=3e5+5; int cl[N]; vector <int> g[N]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,m,k; cin>>n>>m>>k; for(int i=1;i<=n;i++)cin>>cl[i]; while(m--){ int u,v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } int res=0; queue <pair <set <int>,int > > q; for(int i=1;i<=n;i++){ q.push({{cl[i]},i}); while(!q.empty()){ set <int> st=q.front().ff; int v=q.front().ss; q.pop(); for(auto to : g[v]){ if(st.find(cl[to])==st.end()){ st.insert(cl[to]); res++; q.push({st,to}); st.erase(cl[to]); } } } } cout<<res<<"\n"; } /* 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...