Submission #838518

#TimeUsernameProblemLanguageResultExecution timeMemory
838518vjudge1Paths (BOI18_paths)C++17
23 / 100
3029 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const long long maxn=1e6 + 10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n,m,k; cin>>n>>m>>k; int x[n]; vector<int>g[n]; for(int i=0;i<n;i++) { cin>>x[i]; x[i]--; } for(int i=0;i<m;i++) { int l,r; cin>>l>>r; l--;r--; g[l].push_back(r); g[r].push_back(l); } int ans=0; for(int i=0;i<n;i++) { vector<int>c(5); c[x[i]]=1; queue<vector<int>>Q; Q.push({i}); Q.push({1}); Q.push(c); while(!Q.empty()) { int teme=Q.front()[0];Q.pop(); int pat=Q.front()[0];Q.pop(); vector<int>co=Q.front();Q.pop(); if(pat<=k && co[0]<2 && co[1]<2 && co[2]<2 && co[3]<2) { ///cout<<i<< " "<< pat<<" "<<teme<<" "<<co[0]<<endl; ans++; } for(auto ax:g[teme]) { int col=x[ax]; if(co[col]+1<2) { vector<int>pomcol; pomcol=co; pomcol[col]++; Q.push({ax}); Q.push({pat+1}); Q.push(pomcol); } } } } cout<<ans-n<<endl; 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...