QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#34207 | #4235. Transparency | Heltion# | WA | 4ms | 3716kb | C++20 | 3.1kb | 2022-06-06 00:21:00 | 2022-06-06 00:21:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int s, p, t;
cin >> s >> p >> t;
vector<int> pp(s + 1);
for (int i = 0, u; i < p; i += 1) {
cin >> u;
pp[u] = 1;
}
vector<vector<pair<int, char>>> G(s + 1);
vector th(s + 1, vector<int>(26, -1));
for (int i = 0, u, v; i < t; i += 1) {
char c;
cin >> u >> c >> v;
G[u].emplace_back(v, c);
if (isupper(c))
th[u][c - 'A'] = v;
}
int ans = -1;
vector fd(s + 1, vector<int>(s + 1, -1));
vector sd(s + 1, -1);
for (int i = 1; i <= s; i += 1) {
queue<int> q;
for (auto [v, w] : G[i])
if (islower(w) and fd[i][v] == -1) {
fd[i][v] = 1;
q.push(v);
}
while (not q.empty()) {
int u = q.front();
q.pop();
for (auto [v, w] : G[u])
if (islower(w) and fd[i][v] == -1) {
fd[i][v] = fd[i][u] + 1;
q.push(v);
}
}
}
{
sd[1] = 0;
queue<int> q;
q.push(1);
while (not q.empty()) {
int u = q.front();
q.pop();
for (auto [v, w] : G[u])
if (sd[v] == -1) {
sd[v] = sd[u] + 1;
q.push(v);
}
}
}
auto update = [&](int& x, int y) {
if (x == -1 or y < x) {
x = y;
return true;
}
return false;
};
if (0)
for (int i = 1; i <= s; i += 1)
if (pp[i])
for (int j = 1; j <= s; j += 1)
if (pp[j])
if (sd[i] != -1 and fd[i][j] != -1)
update(ans, sd[i] * 2 + fd[i][j]);
vector d(s + 1, vector<int>(s + 1, -1));
queue<pair<int, int>> q;
for (int i = 1; i <= s; i += 1)
if (sd[i] != -1) {
for (auto [v1, w1] : G[i])
for (auto [v2, w2] : G[i])
if (w1 != w2 and islower(w1) and islower(w2)) {
if (update(d[v1][v2], sd[i] * 2 + 2))
q.emplace(v1, v2);
}
}
while (not q.empty()) {
auto [u1, u2] = q.front();
//cout << u1 << " " << u2 << " " << d[u1][u2] << endl;
q.pop();
if (pp[u1] and pp[u2]) {
update(ans, d[u1][u2]);
}
for (auto [v1, w1] : G[u1])
if (islower(w1) and update(d[v1][u2], d[u1][u2] + 1))
q.emplace(v1, u2);
for (auto [v2, w2] : G[u2])
if (islower(w2) and update(d[u1][v2], d[u1][u2] + 1))
q.emplace(u1, v2);
for (int i = 0; i < 26; i += 1)
if (th[u1][i] != -1 and th[u2][i] != -1
and update(d[th[u1][i]][th[u2][i]], d[u1][u2] + 2))
q.emplace(th[u1][i], th[u2][i]);
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 3716kb
input:
4 1 8 3 1 F 1 1 A 2 2 b 1 2 F 3 2 d 3 3 B 3 3 y 4 4 d 1
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3692kb
input:
4 1 8 3 1 F 1 1 A 2 2 b 1 2 F 3 2 d 3 3 B 3 3 y 4 4 d 4
output:
-1
result:
ok single line: '-1'
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 3648kb
input:
5 2 5 1 5 1 i 2 2 c 3 3 p 4 4 c 1 1 I 5
output:
-1
result:
wrong answer 1st lines differ - expected: '4', found: '-1'