답안 #1095303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095303 2024-10-01T20:01:20 Z andrewp Paths (BOI18_paths) C++14
70 / 100
237 ms 45904 KB
//Dedicated to my love, ivaziva
#pragma GCC optimize("Ofast") 
#include <bits/stdc++.h> 
using namespace std;  

#define int long long 
 
using pii = pair<int, int>;
using ll = int64_t; 
 
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define dbg(x) cerr<<#x<<": "<<x<<'\n';  
#define dbga(A,l_,r_){for(int i_=l_;i_<=r_;i_++)cerr<<A[i_]<<' ';cerr<<'\n';}
#define dbgv(a_){for(auto x_:a_) cerr<<x_<<' ';cerr<<'\n';}   

const int N = 3e5 + 20;
int n, m, k, a[N], ans;
vector<int> g[N];
int32_t main()  {
    ios::sync_with_stdio(false); cin.tie(nullptr);  
    cout.tie(nullptr); cerr.tie(nullptr);

    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i]; 
    }
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    } 
    ans = 0;
    if (k >= 2) {
        for (int i = 1; i <= n; i++) {
            for (int u : g[i]) {
                if (a[u] != a[i]) {
                    ans++;
                }
            }
        }
    }
    if (k >= 3) {
        for (int i = 1; i <= n; i++) {
            vector<int> cnt(k + 1, 0);
            for (int u : g[i]) {
                cnt[a[u]]++;
            }
            for (int x = 1; x <= k; x++) {
                for (int y = 1; y <= k; y++) {
                    if (x != y && x != a[i] && y != a[i]) {
                        ans += cnt[x] * cnt[y];
                    }
                }
            }
        }
    } 
    dbg(ans);
    if (k >= 4) {
        vector<vector<int>> cnt(n + 1, vector<int>(k + 1, 0));
        for (int i = 1; i <= n; i++) {
            for (int u : g[i]) {
                cnt[i][a[u]]++;
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int u : g[i]) {     
                int uk = 0;     
                for (int x = 1; x <= k; x++) {
                    for (int y = 1; y <= k; y++) {
                        if (x != y && a[i] != a[u] && x != a[i] && x != a[u] && y != a[i] && y != a[u]) { 
                            ans += cnt[i][x] * cnt[u][y];                
                        }
                    }
                }    
            }
        }
    } 
    cout << ans << '\n';
    return 0;
}

Compilation message

paths.cpp: In function 'int32_t main()':
paths.cpp:69:21: warning: unused variable 'uk' [-Wunused-variable]
   69 |                 int uk = 0;
      |                     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7276 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 5 ms 7360 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 17424 KB Output is correct
2 Correct 34 ms 16720 KB Output is correct
3 Correct 151 ms 24656 KB Output is correct
4 Correct 59 ms 19024 KB Output is correct
5 Correct 63 ms 19028 KB Output is correct
6 Correct 88 ms 21952 KB Output is correct
7 Correct 139 ms 24700 KB Output is correct
8 Correct 110 ms 25344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7276 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 5 ms 7360 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 43 ms 17424 KB Output is correct
12 Correct 34 ms 16720 KB Output is correct
13 Correct 151 ms 24656 KB Output is correct
14 Correct 59 ms 19024 KB Output is correct
15 Correct 63 ms 19028 KB Output is correct
16 Correct 88 ms 21952 KB Output is correct
17 Correct 139 ms 24700 KB Output is correct
18 Correct 110 ms 25344 KB Output is correct
19 Correct 42 ms 17556 KB Output is correct
20 Correct 34 ms 16900 KB Output is correct
21 Correct 125 ms 24660 KB Output is correct
22 Correct 64 ms 18992 KB Output is correct
23 Correct 54 ms 19028 KB Output is correct
24 Correct 85 ms 21960 KB Output is correct
25 Correct 123 ms 24660 KB Output is correct
26 Correct 127 ms 25356 KB Output is correct
27 Correct 51 ms 16720 KB Output is correct
28 Correct 73 ms 19180 KB Output is correct
29 Correct 220 ms 45904 KB Output is correct
30 Correct 143 ms 31932 KB Output is correct
31 Correct 144 ms 31936 KB Output is correct
32 Correct 237 ms 45812 KB Output is correct
33 Correct 4 ms 7516 KB Output is correct
34 Correct 3 ms 7516 KB Output is correct
35 Correct 3 ms 7516 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 3 ms 7312 KB Output is correct
38 Correct 4 ms 7532 KB Output is correct
39 Correct 4 ms 7516 KB Output is correct
40 Correct 4 ms 7516 KB Output is correct
41 Correct 3 ms 7516 KB Output is correct
42 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7512 KB Output is correct
2 Incorrect 21 ms 10448 KB Output isn't correct
3 Halted 0 ms 0 KB -