Submission #957944

# Submission time Handle Problem Language Result Execution time Memory
957944 2024-04-04T14:02:14 Z vjudge1 Paths (BOI18_paths) C++17
23 / 100
3000 ms 1048576 KB
//* Nigga we hit em up like mutherfucking Tupac Shakur

#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
      
using namespace std;
using namespace __gnu_pbds;
      
template <typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag, tree_order_statistics_node_update>;
      
#define int long long
          
#define pb push_back
#define ins insert
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
  
          
using ll = long long;
using ld = long double;

#define endl '\n'

#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
        
#define da cout<<"DA"<<endl
#define ne cout<<"NE"<<endl
          
#define send ios::sync_with_stdio(false);
#define help cin.tie(0);
          
void solve(int T);
          
const int N = 1e5  + 10;
const int M = 5e5 + 10;
const int SQRT = sqrt(N);
const int LOG = 20;
const int INF = 1e18;
const int MOD = 123456789;
const ld EPS = 1e-9;

  
int ans;
int n, m,k, q, l, r, x, y, z, mx, mn;
  
  
          
int32_t main(){
    auto begin = chrono::high_resolution_clock::now();
    cout<<setprecision(7)<<fixed;
              
    send help;
          
    int tt = 1;
    //cin>>tt; //? Comment if no testcases
    for(int i = 1;i<=tt;i++){
        cerr<<"Case "<<i<<": "<<endl;
        solve(i);
    }
    auto end = chrono::high_resolution_clock::now();
    cerr<<"Time: "<<chrono::duration_cast<chrono::duration<double>>(end - begin).count()<<endl;
    return 0;
}

vector<int> g[N];

int A[N];


void f(int x){
    queue<pair<int,int> > q;


    q.push({x, (1 << A[x])});

    while(q.size()){
        auto [u, msk] = q.front();
        q.pop();
        ans++;
        for(auto v : g[u]){
            if((1 << A[v]) & msk)continue;
            int nmsk = msk | (1 << A[v]);

            q.push({v, nmsk});
        }
    }
}

void solve(int T){
    cin>>n>>m>>k;
    for(int i = 0;i<n;i++){
        cin>>A[i];
        --A[i];
    }

    for(int i = 0;i<m;i++){
        int u, v;
        cin>>u>>v;
        --u, --v;
        g[u].pb(v);
        g[v].pb(u);
    }

    for(int i = 0;i<n;i++){
        int prev = ans;
        f(i);
       // cout<<i+1<<": "<<ans - prev<<endl;
    }
    cout<<ans - n<<endl;
}   
  
  
  
//! Te molam da raboti !!

Compilation message

paths.cpp: In function 'void solve(long long int)':
paths.cpp:111:13: warning: unused variable 'prev' [-Wunused-variable]
  111 |         int prev = ans;
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2326 ms 13464 KB Output is correct
2 Execution timed out 3046 ms 14652 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 2326 ms 13464 KB Output is correct
12 Execution timed out 3046 ms 14652 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Runtime error 1392 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -