Submission #767905

# Submission time Handle Problem Language Result Execution time Memory
767905 2023-06-27T09:19:52 Z raysh07 Paths (BOI18_paths) C++17
0 / 100
3 ms 3084 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e5 + 69;
int a[maxn];
vector <int> adj[maxn];
int n;
int cnt = 0;
vector <int> v;
vector <int> col;
bool vis[maxn];
int colpre[5];

void dfs(int u, int parent)
{
    //vis[u] = true;
    //cout<<"Vertex "<<u<<" Colours : "<<"\n";
    //for (int i=0; i<(int)(col.size()); i++)
    //cout<<col[i]<<" ";
    //cout<<"\n";
    if (colpre[a[u]] ==1)
    return;
    colpre[a[u]] = 1;
    v.push_back(u);
    for (int v:adj[u])
    {
        //if (!vis[v])
        if (v!=parent)
        dfs(v, u);
    }
    colpre[a[u]] = 0;
}

void Solve() 
{
    cin>>n;
    for (int i=1; i<=n; i++){
    cin>>a[i];a[i]--;
    }
    for (int i=1; i<n; i++)
    {
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    for (int i=1; i<=n; i++)
    {
        v.clear();
        col.clear();
        //for (int j=1; j<=n; j++)
        //{
         //   cout<<vis[j]<<" ";
        //}
        //cout<<"\n";
        //cout<<"First "<<i<<"\n";
        for (int i=0; i<5; i++)
        colpre[i] = 0;
        
        dfs(i, -1);
        cnt+= v.size()-1;
        
      //  for (int j=0; j<(int)(v.size()); j++){
    //    vis[v[j]] = false;
        //cout<<v[j]<<" ";
      //  }
        //cout<<"\n";
    }
    cout<<cnt;
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -