QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#34201 | #4235. Transparency | Heltion# | WA | 3ms | 3724kb | C++20 | 3.0kb | 2022-06-06 00:01:27 | 2022-06-06 00:01:29 |
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);
vector th(s + 1, vector<int>(26, -1));
for (int i = 0, u; i < p; i += 1) {
cin >> u;
pp[u] = 1;
}
vector<vector<pair<int, char>>> G(s + 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;
};
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[u1])
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3724kb
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: 0ms
memory: 3576kb
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: 0
Accepted
time: 3ms
memory: 3572kb
input:
5 2 5 1 5 1 i 2 2 c 3 3 p 4 4 c 1 1 I 5
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
8 2 96 4 8 1 x 2 1 y 5 2 A 3 3 A 4 4 A 2 5 A 6 6 A 7 7 A 8 8 A 5 5 B 2 6 B 2 7 B 2 8 B 2 5 C 2 6 C 2 7 C 2 8 C 2 5 D 2 6 D 2 7 D 2 8 D 2 5 E 2 6 E 2 7 E 2 8 E 2 5 F 2 6 F 2 7 F 2 8 F 2 5 G 2 6 G 2 7 G 2 8 G 2 5 H 2 6 H 2 7 H 2 8 H 2 5 I 2 6 I 2 7 I 2 8 I 2 5 J 2 6 J 2 7 J 2 8 J 2 5 K 2 6 K 2 7 K 2 8...
output:
24
result:
ok single line: '24'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
4 1 4 1 1 d 2 2 A 3 3 A 4 4 d 1
output:
-1
result:
ok single line: '-1'
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 3576kb
input:
7 1 8 1 1 d 2 2 A 3 3 A 4 4 d 1 1 A 5 5 d 6 6 d 7 7 A 1
output:
-1
result:
wrong answer 1st lines differ - expected: '8', found: '-1'