QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784096 | #8874. Labelled Paths | alexhamidi | TL | 728ms | 6792kb | C++20 | 1.4kb | 2024-11-26 13:20:47 | 2024-11-26 13:20:48 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m, d, s;
cin >> n >> m >> d >> s;
string A; //all edge labels are substrings of A
cin >> A;
vector<pair<string, int>> adj[n+1]; //target, substring
for (int i = 0; i < m; i++) {
int u, v, p, l;
cin >> u >> v >> p >> l;
adj[u].push_back({A.substr(p-1, l), v});
}
for (int i = 1; i <= n; i++) {
vector<pair<string, vector<int>>> wrk;
vector<pair<string, vector<int>>> cmp;
wrk.push_back({"",{s}});
while (!wrk.empty()) {
vector<pair<string, vector<int>>> cwrk;
for (auto [s, vec] : wrk) {
int ln = vec.back();
if (ln == i) {
cmp.push_back({s, vec});
} else for (auto [newS, v] : adj[ln]) {
vector<int> tmp = vec;
tmp.push_back(v);
cwrk.push_back({s+newS, tmp});
}
}
wrk = cwrk;
}
if (cmp.empty()) {
cout << 0;
} else {
auto [_, bestPath] = *min_element(cmp.begin(), cmp.end());
cout << bestPath.size() << " ";
for (auto node : bestPath) cout << node << " ";
}
cout << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
11 30 105 9 fufuffuffuuuuuufuffuffuufffuufufuuuuuuuuuufffufufffuuufuffufufuuffffuufffuffffuffffufuuuufuufuuffuuuufffu 1 6 51 1 5 2 6 1 9 6 57 3 11 8 86 4 10 8 95 0 6 2 17 0 6 3 78 0 7 3 50 0 11 4 98 3 10 3 77 3 5 4 18 4 7 4 81 1 9 7 82 0 1 3 79 2 7 5 13 4 1 10 86 2 10 4 10 0 9 3 4 0 6 11 10 4 6 4 82...
output:
2 9 1 3 9 1 2 2 9 3 3 9 7 4 3 9 1 5 3 9 1 6 2 9 7 6 9 1 5 6 3 8 1 9 3 9 1 10 3 9 7 11
result:
ok good!
Test #2:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
12 35 74 2 iggigggggiigiggggiigggigigiiggiiigiigiggiggiiggiiiigigggggigggggigggggggii 6 4 1 1 8 10 9 4 11 7 1 0 6 10 11 0 12 10 30 4 3 1 11 1 1 9 35 2 2 1 24 4 7 10 15 0 3 5 31 0 3 11 11 1 1 4 67 2 2 5 19 4 9 4 32 0 2 6 48 1 8 9 49 0 7 9 39 1 8 12 61 4 12 7 54 0 12 4 22 4 6 9 73 0 9 10 13 3 2 8 71 4...
output:
2 2 1 1 2 0 5 2 12 7 9 4 3 2 8 5 3 2 8 6 3 2 12 7 2 2 8 4 2 12 7 9 4 2 12 7 10 0 2 2 12
result:
ok good!
Test #3:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
11 31 101 2 vvvcvcvvccccvccvcvvvvccccvvcccccvccccvcvcccccvcvvvvcvcvcvcccvccccvcccvccccccvvvvvccvvcvvcvvvvvccvccvv 2 9 41 3 6 1 60 4 2 11 78 2 2 8 58 0 9 1 54 0 2 6 48 4 3 10 85 1 3 6 45 3 3 4 19 0 2 4 33 1 8 4 51 3 2 1 19 4 7 6 56 1 3 8 77 1 9 5 31 0 5 4 56 2 7 10 66 0 8 11 70 4 9 7 69 4 1 5 86 3 1 ...
output:
4 2 8 9 1 1 2 0 4 2 8 9 4 4 2 8 9 5 4 2 9 7 6 3 2 9 7 2 2 8 3 2 8 9 4 2 9 7 10 5 2 8 9 5 11
result:
ok good!
Test #4:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
10 27 98 10 pppccccppppcccccpccppcccccccccpccpcpccppcppcpppppppppccpccppppppcpcpcpccpppccccccppcppcpppcpccpcpp 1 3 26 1 3 9 81 0 10 3 42 3 2 1 26 4 7 8 15 0 1 4 43 4 2 3 9 0 1 8 10 1 3 8 71 0 2 7 62 2 7 5 55 3 1 9 45 3 7 4 14 4 4 5 13 0 10 6 88 3 2 5 4 3 6 4 61 2 2 8 1 4 9 5 75 4 7 1 74 1 8 6 1 1 10...
output:
3 10 2 1 2 10 2 3 10 7 3 5 10 7 3 9 4 3 10 2 5 6 10 2 1 3 8 6 2 10 7 2 10 8 4 10 7 3 9 1 10
result:
ok good!
Test #5:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
14 42 84 3 mwmwmwwwwmmwmmwmmmwmwwwmwwwmmmwmwmwwwmmwwmmmwwwmmwmmmwmmmmmmmwmmwwwwmwwmwwwmwmwwwwmw 2 4 43 1 4 12 62 0 9 11 29 0 10 14 7 4 2 6 78 2 13 12 1 0 3 14 17 3 3 4 13 0 9 6 38 0 1 4 75 0 10 3 17 4 11 12 64 0 10 8 20 2 1 11 64 2 1 9 31 4 4 7 74 0 1 6 44 1 1 14 3 0 7 8 2 4 10 9 65 0 2 14 29 2 5 14...
output:
2 3 1 4 3 9 5 2 1 3 2 3 4 3 3 9 5 3 3 1 6 3 3 4 7 5 3 9 4 7 8 2 3 9 0 2 3 11 3 3 4 12 3 3 4 13 3 3 1 14
result:
ok good!
Test #6:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
13 38 144 9 lvvlllvlvllvvvvvvvvvvlvvvlvlvllllllvlllvlvlvllvllvllvlvvvllvvvvvllllllllvllvllvlllllvvlvlvvlllvvvllllllvvvlllvvvvllvlvlllvllllvvvvvlvvlvvvlllvvl 4 2 94 3 3 4 142 3 1 5 135 2 3 7 56 0 1 2 17 2 11 13 97 4 13 8 39 1 12 4 22 4 8 10 117 1 9 3 145 0 6 2 82 2 6 13 65 3 9 4 82 2 3 6 45 0 12 7 55...
output:
4 9 3 6 1 4 9 3 6 2 2 9 3 2 9 4 3 9 3 5 3 9 3 6 3 9 3 7 3 9 3 8 1 9 4 9 3 8 10 0 3 9 6 12 4 9 3 7 13
result:
ok good!
Test #7:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
11 30 109 9 eeqqeqqeeqqeqeeqeeeqeeqqeeqqeqqqqqeeeqeqeqeqeeqeeqqeeeeeeeqeeqqeeeqeeqeqqeeqqeqqeeqeqqeeqqeqqeqqeqqeqeqeqqeeq 3 7 28 0 8 5 4 1 9 3 4 2 2 3 53 1 6 4 31 1 4 7 55 2 10 1 89 0 9 5 54 0 11 7 59 1 2 5 107 3 1 5 60 3 9 8 74 3 8 11 105 1 10 3 55 0 9 6 18 0 11 6 17 1 3 5 48 1 11 3 36 1 2 1 101 2 ...
output:
3 9 10 1 2 9 2 3 9 10 3 3 9 10 4 2 9 5 2 9 6 4 9 10 3 7 2 9 8 1 9 2 9 10 3 9 8 11
result:
ok good!
Test #8:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
14 42 122 10 oojoojojjojjojojooojjojjojoooojjoojojooooooojjojjoojojjjojjojjojjojoojjooooojjjoojojojjoooojjjojoojjojjjjjjjojoojooojooooo 11 3 56 1 3 12 84 1 8 1 118 4 13 6 98 1 8 14 89 4 8 9 123 0 8 5 4 0 10 9 46 0 7 4 89 0 7 13 75 0 5 6 77 1 10 14 53 4 12 8 106 0 10 3 109 1 8 6 16 1 12 14 93 0 2 13 ...
output:
7 10 11 3 12 8 5 1 2 10 2 3 10 11 3 4 10 2 7 4 6 10 2 7 13 8 5 7 10 2 7 13 8 5 6 3 10 2 7 5 10 2 7 13 8 6 10 2 7 13 8 9 1 10 2 10 11 4 10 11 3 12 4 10 2 7 13 7 10 2 7 13 8 5 14
result:
ok good!
Test #9:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
15 39 89 6 ufxxuxxuffxxuuffuuffufxxuxxxufxfuuuxfffxufufxffxfxfufuuxfxfffxxuuuxfxxuffufuffxfffxffuuff 10 13 50 0 7 11 28 0 1 15 77 1 13 3 80 4 6 10 78 3 14 13 62 4 8 2 45 0 14 10 86 3 15 12 37 4 13 12 39 1 2 15 9 3 15 5 56 0 12 9 29 3 6 4 32 2 8 5 74 4 7 3 12 3 10 12 10 2 14 15 40 3 8 12 30 4 8 11 60...
output:
2 6 1 4 6 10 13 2 4 6 15 5 3 2 6 4 3 6 15 5 1 6 0 0 3 6 15 9 2 6 10 3 6 15 11 4 6 1 15 12 3 6 10 13 3 6 1 14 2 6 15
result:
ok good!
Test #10:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
14 41 110 9 jjljljjljjjjljljjjlljljjllljlllljlljljjjljjlljljjljljlljljjjljlllllljjllljljjjjlljlljljllljjjjjjljjjljlllljlll 9 8 77 2 6 13 22 0 14 8 80 1 11 5 68 4 14 13 22 4 9 10 10 4 12 7 24 3 7 3 16 1 9 12 92 2 11 3 25 3 11 1 8 3 14 5 70 1 6 4 20 2 13 3 104 0 14 11 97 0 4 8 42 0 10 2 70 0 1 6 99 0 ...
output:
4 9 12 11 1 3 9 11 2 6 9 11 2 8 13 3 4 9 10 7 4 5 9 11 2 8 5 5 9 12 11 1 6 3 9 10 7 4 9 11 2 8 1 9 2 9 10 2 9 11 2 9 12 5 9 11 2 8 13 0
result:
ok good!
Test #11:
score: 0
Accepted
time: 728ms
memory: 6496kb
input:
93 486 2044 93 yyyyrrrryyyrryyyrryyyyyyryyyyyrrrryyyyyyyyyyyrryrryyrryyrryyyrrryyrrryyyryyyryyryryryyryyryryyyrrrrryrrrrryrryyyyrryyyryrrrryryyrryyyyyryryryyyyryrrryyyryyyrryryyrrrrryryryrrrryyryryrrryrrryyyyyyyrrrrryyyrrrrryrrryrryrryyrryyyrryyrryrrryryyrrryyyrrrryyryyyrrryryrrrrryyrrrrrryyrrryrryy...
output:
3 93 40 1 0 5 93 60 78 48 3 6 93 60 78 48 3 4 5 93 60 78 48 5 5 93 40 29 49 6 4 93 52 88 7 3 93 79 8 4 93 40 22 9 0 4 93 52 85 11 5 93 60 78 48 12 5 93 60 78 53 13 5 93 60 78 53 14 2 93 15 0 5 93 60 78 84 17 4 93 60 47 18 6 93 52 73 38 34 19 0 4 93 40 1 21 3 93 40 22 5 93 52 88 7 2...
result:
ok good!
Test #12:
score: 0
Accepted
time: 648ms
memory: 6528kb
input:
84 454 2025 63 iajiiiiaijiijajiijiiaajiiaaaaaiaajjaaaijiajaaiijjjjiaijiaiiaijajaijijjaiajiajjjajiajijaiiaaiijaiajijjiiajjaajajjjiiajjiajjjiaajiijjiaaaaajjiiiiaaaiajaaiajjiaajaajjiajaajijaaijijaajaajaiajjiajajjaijjijaiiiiiaaiiijijaiaiiijjiaiaajjijaiaijjjaaijjajijjiijjjaijaaiiijaijaajaijaaiajajiaaajjj...
output:
3 63 38 1 5 63 22 7 83 2 3 63 22 3 3 63 22 4 0 8 63 22 61 12 74 27 26 6 3 63 22 7 4 63 22 69 8 3 63 22 9 3 63 38 10 4 63 22 75 11 3 63 61 12 7 63 22 61 12 74 31 13 0 5 63 42 31 25 15 4 63 42 31 16 4 63 22 7 17 4 63 22 56 18 9 63 22 61 12 74 27 16 77 19 5 63 38 10 47 20 0 2 63 22 3...
result:
ok good!
Test #13:
score: 0
Accepted
time: 130ms
memory: 4208kb
input:
89 414 1291 1 xxxxxyxyyxyyyxxyxxxyxxyxyyyyxyxxyyxyyyyyxxxyyxyyyyxxxxxxyyyyyxxxyxyxxyyyxyyxxxxyyxxxyxyyxyxyyyxxxyyyxxxxxxyxyyxyxxxyyyyxyxxxxxyyyxyyxyyyxyxxxyyyxxxyxxyyxxxyyxyyyxyxyyxxyyxxyyyyxyxxxyxxxxyxxyyxyyxxxyxxxyxxyxxxyxxyyyxxxyxxxxyyxyyyxyyxxyxyxxyxyxxyyyxxyyyyyxyxxxyxxxyyyxyxyxyxxyyxxxxyyxxxyy...
output:
1 1 5 1 4 47 23 2 6 1 4 47 23 35 3 2 1 4 7 1 14 12 35 84 46 5 4 1 4 52 6 4 1 65 17 7 2 1 8 3 1 8 9 0 5 1 45 41 21 11 3 1 4 12 4 1 8 75 13 2 1 14 3 1 45 15 5 1 4 47 34 16 3 1 65 17 4 1 45 4 18 5 1 14 44 57 19 6 1 4 47 34 59 20 4 1 45 41 21 0 4 1 4 47 23 4 1 45 41 24 6 1 4 47 34 ...
result:
ok good!
Test #14:
score: 0
Accepted
time: 61ms
memory: 3960kb
input:
67 310 1035 30 rggggrgggrgggrggrggrgggggrggrggggrgrggrrggggrrrgrrrggggrgggrggrgrggrrggrggrrggggrgrgrrgrgrrgggggggrgrrgggrgrggggrrggrgrgrggggrgrggggrggrrrrrggrgrggrgrrggrrgggrgrrgrgrgrgrgrggrrrrrgrrgrrgggrrrggrggggrrgrrggrrggrrgggrgrrrrrrrrrgrrrgrggrggggrrrggrrgggrrggrgrrggrggggrrrrgrrrrggrrrgrgggrrg...
output:
3 30 31 1 4 30 31 59 2 3 30 42 3 3 30 7 4 4 30 31 29 5 4 30 7 4 6 2 30 7 7 30 31 29 33 63 50 8 8 30 7 4 43 64 63 48 9 4 30 31 59 10 8 30 7 4 43 64 60 50 11 7 30 7 4 43 64 13 12 6 30 7 4 43 64 13 6 30 31 59 52 32 14 4 30 31 59 15 0 7 30 31 29 33 43 64 17 7 30 7 4 43 64 60 18 6 30 7 4...
result:
ok good!
Test #15:
score: 0
Accepted
time: 169ms
memory: 4540kb
input:
87 451 2564 61 foofofoffffoffooofooffooofofooffooffoofffoffffoooffooooofoofoofffffffffofoooffffofofoffofooffofofofofoooffofoooffooofofoofooofofffoofofooooofooffoffoffoffoffffffffofffffffofofoofooffffffoooooooooffffooooofoooofoofffffoofoooofffffooooofffoffoooffoofooffooooffoooooooffoofffoofoooofffoff...
output:
6 61 15 51 6 35 1 4 61 8 29 2 0 5 61 8 29 2 4 4 61 8 29 5 4 61 15 51 6 2 61 7 2 61 8 0 3 61 81 10 4 61 15 51 11 5 61 8 51 37 12 0 5 61 8 21 49 14 2 61 15 3 61 8 16 5 61 15 51 80 17 5 61 8 51 37 18 5 61 15 51 37 19 6 61 15 51 37 53 20 3 61 8 21 4 61 8 29 22 5 61 8 21 66 23 4 61 8 ...
result:
ok good!
Test #16:
score: 0
Accepted
time: 64ms
memory: 3928kb
input:
53 281 805 1 vrvrrvvrvrvrvrrrvvrrrvrrvvvvvvrvvvvvvrrvrvvrvrvvvrvvrrrrrrrrvvrvrrrvvrrvrvvrrrvvvrrvvrvrrrvvvrrrrrvrrrrrrvrrrrrrvvvrvrrrrvvvvrrvvvvvvvvvvrrrvvrvrrrrrvrvvvvvrrrrvrvrrvvrrvrvvvvrrrrvrvrrvrrrrvrvrvvvvrvvrrvrvvrrvrvrrvrrrrrvvvvvrvrvrvrvrvvvvvrvrvvvrvvvrvvvvrvrvvvvvrvvvrvvrrvrrvrvrrrrrrvvvrv...
output:
1 1 3 1 9 2 0 0 5 1 23 41 43 5 3 1 9 6 5 1 23 27 39 7 4 1 15 52 8 2 1 9 3 1 23 10 5 1 23 10 29 11 0 5 1 23 27 39 13 5 1 23 27 39 14 2 1 15 0 5 1 23 41 43 17 5 1 23 19 53 18 3 1 23 19 5 1 9 49 48 20 0 3 1 9 22 2 1 23 4 1 23 10 24 4 1 9 36 25 6 1 23 41 43 15 26 3 1 23 27 4 1 23 4...
result:
ok good!
Test #17:
score: 0
Accepted
time: 180ms
memory: 4624kb
input:
78 337 1082 28 uttuuuutttuttuuuuuttuuuuttutuuttututtuuttututututututtttuututttuuutuuttutututttuututtttututuututuututtuuutututtutuutuututuutuutttutttuuttututututtttuuttuutuuuutttttututttuuttttutuututtttuuuuuuututtututttuututtuutuuuutuuutututuuuuuuuttttutuuuuttttuuuttuututuututuutuuttttuuttutuuttttuuu...
output:
2 28 1 4 28 56 11 2 3 28 1 3 0 6 28 23 56 47 36 5 0 3 28 62 7 0 2 28 9 5 28 56 47 41 10 3 28 56 11 3 28 1 12 7 28 23 56 11 22 27 13 8 28 23 56 47 36 24 39 14 8 28 23 56 47 36 22 35 15 0 3 28 1 17 7 28 23 56 11 75 43 18 7 28 23 56 47 36 1 19 0 7 28 23 56 11 22 33 21 5 28 23 56 11 22 ...
result:
ok good!
Test #18:
score: 0
Accepted
time: 186ms
memory: 4444kb
input:
72 425 2017 43 jggggjgjgggggggjggggjggggjggjgjggjjgjjjgjggjjjgggjgjgjggjjjjjjjggjgjjgggjgggjgjggjggggggjggjggjggjjjggjggjjgjjgggggjjjjgggjjggjjjjjjgggjjgjgjjjgjggjjgjjgjjgjgjjjjgjjgjggjjgggjjjjjjgjjjgjjggggggggjgjjgjjjjgggggjgjggggggjjgjjjgggggjgggggjjjjjgjgjjgjjjgjgjjggjjggjjgjgjgjjjggjjjjgjgggjgjj...
output:
0 3 43 23 2 2 43 3 4 43 3 20 4 4 43 3 10 5 0 7 43 12 11 56 63 72 7 0 3 43 64 9 3 43 3 10 3 43 12 11 2 43 12 7 43 12 11 56 63 72 13 0 4 43 12 11 15 0 3 43 64 17 0 5 43 12 11 15 19 3 43 3 20 0 10 43 12 11 56 63 28 29 39 55 22 2 43 23 5 43 12 11 44 24 5 43 12 11 56 25 5 43 23 47 42 26...
result:
ok good!
Test #19:
score: 0
Accepted
time: 634ms
memory: 6792kb
input:
81 403 1327 27 mmcmmmcmmmmmcmmcccccmmmmccmcmccmcmcmmmmmcmmmmmccmmmcccmmccccccmccmcmcccmmccmmmcmccmmmmcmmmmmmmmcmcccmmccmcmcccmmmmmmmmcmmccmmcmmcmmccmmmmmmmccccmmccmccccccmcmccmcmcmccmcmcmmmcmcmcccmmmcmmccmcmmcccccmmmccmcmcmmmmcmmmccccmccmmmmcccmcmmmcmcccmmcmmccmmcmmcmmmmmmmmmmccccmcmmmmcmccmmccmcccc...
output:
0 0 6 27 34 52 31 19 3 7 27 34 52 31 55 71 4 3 27 74 5 11 27 34 52 31 55 71 63 48 58 5 6 8 27 34 52 54 25 42 55 7 0 9 27 34 52 31 55 71 20 15 9 4 27 13 71 10 0 10 27 34 52 31 55 71 63 48 28 12 2 27 13 0 7 27 34 52 75 42 77 15 3 27 74 16 4 27 74 5 17 2 27 18 5 27 34 52 31 19 4 27 74 79 ...
result:
ok good!
Test #20:
score: 0
Accepted
time: 163ms
memory: 4196kb
input:
90 443 1653 58 xxgxxgxxggxxxxgggxxxxgxggggxxgxggggxgggggxggxgxgggxxgggxxggxgxxxgggxgxxxgggxxxggxxggxgxggggxgxgxxxgxggxggggxggxxgxggggxxxxggxxgxgxxxxxxggxggggxggxgxxggxgxxxggxgxxxggxggxggxgxggxgxxxxggxggxggxgxxgxgxxxxgxxggggxxggxggxxgxgxxxgxgxxxggggxgxxxgxxggxxgggxgxxgxgxxggxggggggxxggxxxxxxxggxgggxx...
output:
7 58 72 81 63 57 88 1 0 7 58 72 81 63 57 62 3 2 58 4 7 58 72 81 63 57 88 5 3 58 24 6 0 0 5 58 4 13 40 9 0 8 58 72 81 63 57 88 71 11 4 58 63 57 12 3 58 4 13 3 58 63 14 3 58 22 15 0 8 58 72 81 63 57 88 60 17 4 58 24 44 18 5 58 22 43 50 19 2 58 20 0 2 58 22 4 58 4 13 23 2 58 24 5 58 6...
result:
ok good!
Test #21:
score: -100
Time Limit Exceeded
input:
47 64 1000 1 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...