Submission #645474

# Submission time Handle Problem Language Result Execution time Memory
645474 2022-09-27T08:12:56 Z mychecksedad Paths (BOI18_paths) C++17
43 / 100
376 ms 49956 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;



int n, m, k, a[N];
ll ans = 0, dp[N][3];
vector<int> g[N];
vector<bool> vis(N);
void dfs(int v, int p){
    vis[v] = 1;
    for(int u: g[v]){
        int mask = (1<<a[v]) + (1<<a[u]);
        if(a[v] != a[u]){
            ans++;
            if(mask == 3) ans += dp[u][2];
            if(mask == 5) ans += dp[u][1];
            if(mask == 6) ans += dp[u][0];
        }
        if(vis[u]) continue;
        dfs(u, v);
    }
}


void dfs1(int v, int p, int d, vector<int> &x){
    if(d>1){    
        ans++;
    }
    for(int u: g[v]){
        if(u != p){
            if(x[a[u]]) continue;
            x[a[u]] = 1;
            dfs1(u, v, d + 1, x);
            x[a[u]] = 0;
        }
    }
}

void solve(){
    cin >> n >> m >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) --a[i], dp[i][0] = dp[i][1] = dp[i][2] = 0;
    for(int i = 0; i < m; ++i){
        int u, v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
        dp[u][a[v]]++;
        dp[v][a[u]]++;
    }
    if(n <= 100){
        vector<int> v (4);
        for(int i = 1; i <= n; ++i){
            v[0] = v[1] = v[2] = v[3] = 0;
            v[a[i]] = 1; 
            dfs1(i, 0, 1, v);
        }
    }else{
        for(int i = 1; i <= n; ++i) if(!vis[i]) dfs(i, 0);
    }


    cout << ans;
}   





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:83:16: warning: unused variable 'aa' [-Wunused-variable]
   83 |     int T = 1, aa;
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB Output is correct
2 Correct 16 ms 23892 KB Output is correct
3 Correct 15 ms 23900 KB Output is correct
4 Correct 15 ms 23936 KB Output is correct
5 Correct 12 ms 23880 KB Output is correct
6 Correct 12 ms 23948 KB Output is correct
7 Correct 12 ms 23836 KB Output is correct
8 Correct 15 ms 23892 KB Output is correct
9 Correct 12 ms 23932 KB Output is correct
10 Correct 12 ms 23856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 27964 KB Output is correct
2 Correct 61 ms 29856 KB Output is correct
3 Correct 336 ms 49940 KB Output is correct
4 Correct 137 ms 34204 KB Output is correct
5 Correct 127 ms 34124 KB Output is correct
6 Correct 198 ms 40556 KB Output is correct
7 Correct 376 ms 44924 KB Output is correct
8 Correct 283 ms 45644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB Output is correct
2 Correct 16 ms 23892 KB Output is correct
3 Correct 15 ms 23900 KB Output is correct
4 Correct 15 ms 23936 KB Output is correct
5 Correct 12 ms 23880 KB Output is correct
6 Correct 12 ms 23948 KB Output is correct
7 Correct 12 ms 23836 KB Output is correct
8 Correct 15 ms 23892 KB Output is correct
9 Correct 12 ms 23932 KB Output is correct
10 Correct 12 ms 23856 KB Output is correct
11 Correct 75 ms 27964 KB Output is correct
12 Correct 61 ms 29856 KB Output is correct
13 Correct 336 ms 49940 KB Output is correct
14 Correct 137 ms 34204 KB Output is correct
15 Correct 127 ms 34124 KB Output is correct
16 Correct 198 ms 40556 KB Output is correct
17 Correct 376 ms 44924 KB Output is correct
18 Correct 283 ms 45644 KB Output is correct
19 Correct 95 ms 30820 KB Output is correct
20 Correct 87 ms 29852 KB Output is correct
21 Correct 298 ms 49956 KB Output is correct
22 Correct 134 ms 34156 KB Output is correct
23 Correct 107 ms 34208 KB Output is correct
24 Correct 201 ms 40580 KB Output is correct
25 Correct 299 ms 45000 KB Output is correct
26 Correct 365 ms 45616 KB Output is correct
27 Incorrect 66 ms 29872 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23932 KB Output isn't correct
2 Halted 0 ms 0 KB -