# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1095287 |
2024-10-01T18:23:35 Z |
andrewp |
Paths (BOI18_paths) |
C++14 |
|
132 ms |
31316 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];
bool was[N];
void dfs(int x) {
was[x] = true;
int f = 0, s = 0, t = 0;
for (int u : g[x]) {
if (a[u] == 1) {
f++;
} else if (a[u] == 2) {
s++;
} else {
t++;
}
if (!was[u]) {
dfs(u);
}
}
if (a[x] == 1) {
ans += 2 * (s * t);
ans += s;
ans += t;
} else if (a[x] == 2) {
ans += 2 * (f * t);
ans += f;
ans += t;
} else {
ans += 2 * (f * s);
ans += f;
ans += s;
}
}
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];
was[i] = false;
}
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;
dfs(1);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
17856 KB |
Output is correct |
2 |
Correct |
38 ms |
16720 KB |
Output is correct |
3 |
Incorrect |
132 ms |
31316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |