Submission #1020190

#TimeUsernameProblemLanguageResultExecution timeMemory
1020190adrielcpPaths (BOI18_paths)C++17
23 / 100
3075 ms10632 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define lld double #define int ll #define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout); template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } // const ll INF = 1e18; const int INF = 1e9; const int mod = 1e9+7; const lld PI = acos(-1.0); int di[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dj[] = {0, 0, 1, -1, 1, -1, 1, -1}; #define debug(x) cout << #x << ": " << x << endl; #define add(a, b) a += b, a %= mod #define mul(a, b) ((a % mod) * (b % mod)) % mod #define all(x) x.begin(),x.end() void solve() { int n,m,k;cin>>n>>m>>k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i], a[i]--; vector<vector<int>> adj(n, vector<int>()); for (int i = 0; i < m; i++) { int u,v;cin>>u>>v;u--;v--; adj[u].push_back(v); adj[v].push_back(u); } int ans = 0; vector<int> cur(k), vis(n); function<void(int)> dfs = [&](int node) { vis[node] = 1; cur[a[node]] = 1; ans++; for (auto children : adj[node]) { if (!vis[children] && !cur[a[children]]) dfs(children); } vis[node] = 0; cur[a[node]] = 0; }; for (int i = 0; i < n; i++) { dfs(i); } cout << ans-n << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0); int t=1; while(t--) solve(); 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...