#include <iostream>
#include <vector>
#include <queue>
#define pii pair<int, int>
#define piii pair<int, pii>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int INF = (int)1e9 + 7;
vector<int> gph[202][8];
vector<int> rgph[202][8];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("in.txt", "r", stdin);
int n, m, s, e; cin >> n >> m >> s >> e; --s; --e;
for(int i = 0; i < m; ++i)
{
int x, y; char c; cin >> x >> y >> c; --x; --y;
int z;
if(c == '<') z = 0;
if(c == '>') z = 1;
if(c == '{') z = 2;
if(c == '}') z = 3;
if(c == '[') z = 4;
if(c == ']') z = 5;
if(c == '(') z = 6;
if(c == ')') z = 7;
gph[x][z].push_back(y);
rgph[y][z].push_back(x);
}
int C[n][n];
for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) C[i][j] = INF;
priority_queue<piii, vector<piii>, greater<piii>> Q;
for(int i = 0; i < n; ++i) Q.push({0, {i, i}});
while(Q.size())
{
auto x = Q.top(); Q.pop();
if(C[x.ee][x.rr] != INF) continue;
C[x.ee][x.rr] = x.ff;
for(int i = 0; i < 8; i += 2)
for(auto j : rgph[x.ee][i])
for(auto k : gph[x.rr][i + 1])
Q.push({x.ff + 2, {j, k}});
for(int i = 0; i < n; ++i)
{
if(C[i][x.rr] > C[x.ee][x.rr] + C[i][x.ee])
Q.push({C[x.ee][x.rr] + C[i][x.ee], {i, x.rr}});
if(C[x.ee][i] > C[x.ee][x.rr] + C[x.rr][i])
Q.push({C[x.ee][x.rr] + C[x.rr][i], {x.ee, i}});
}
}
cout << (C[s][e] == INF ? -1 : C[s][e]);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:31:13: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | int z;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
10 ms |
912 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
15 ms |
1224 KB |
Output is correct |
30 |
Correct |
65 ms |
2116 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
6 ms |
908 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
76 ms |
3664 KB |
Output is correct |
36 |
Correct |
18 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
10 ms |
912 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
15 ms |
1224 KB |
Output is correct |
30 |
Correct |
65 ms |
2116 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
6 ms |
908 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
76 ms |
3664 KB |
Output is correct |
36 |
Correct |
18 ms |
912 KB |
Output is correct |
37 |
Correct |
3 ms |
332 KB |
Output is correct |
38 |
Correct |
153 ms |
6672 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
190 ms |
6700 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
2 ms |
332 KB |
Output is correct |
45 |
Correct |
155 ms |
6740 KB |
Output is correct |
46 |
Correct |
161 ms |
6712 KB |
Output is correct |
47 |
Correct |
3 ms |
588 KB |
Output is correct |
48 |
Correct |
176 ms |
3568 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
319 ms |
6960 KB |
Output is correct |
2 |
Correct |
365 ms |
6812 KB |
Output is correct |
3 |
Correct |
314 ms |
6808 KB |
Output is correct |
4 |
Correct |
313 ms |
6872 KB |
Output is correct |
5 |
Correct |
312 ms |
6824 KB |
Output is correct |
6 |
Correct |
302 ms |
6828 KB |
Output is correct |
7 |
Correct |
311 ms |
6796 KB |
Output is correct |
8 |
Correct |
324 ms |
6960 KB |
Output is correct |
9 |
Correct |
305 ms |
6876 KB |
Output is correct |
10 |
Correct |
320 ms |
6960 KB |
Output is correct |
11 |
Correct |
316 ms |
6856 KB |
Output is correct |
12 |
Correct |
309 ms |
6832 KB |
Output is correct |
13 |
Correct |
284 ms |
6796 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
15 |
Correct |
5 ms |
656 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
10 ms |
912 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
15 ms |
1224 KB |
Output is correct |
30 |
Correct |
65 ms |
2116 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
6 ms |
908 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
76 ms |
3664 KB |
Output is correct |
36 |
Correct |
18 ms |
912 KB |
Output is correct |
37 |
Correct |
3 ms |
332 KB |
Output is correct |
38 |
Correct |
153 ms |
6672 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
190 ms |
6700 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
2 ms |
332 KB |
Output is correct |
45 |
Correct |
155 ms |
6740 KB |
Output is correct |
46 |
Correct |
161 ms |
6712 KB |
Output is correct |
47 |
Correct |
3 ms |
588 KB |
Output is correct |
48 |
Correct |
176 ms |
3568 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
319 ms |
6960 KB |
Output is correct |
51 |
Correct |
365 ms |
6812 KB |
Output is correct |
52 |
Correct |
314 ms |
6808 KB |
Output is correct |
53 |
Correct |
313 ms |
6872 KB |
Output is correct |
54 |
Correct |
312 ms |
6824 KB |
Output is correct |
55 |
Correct |
302 ms |
6828 KB |
Output is correct |
56 |
Correct |
311 ms |
6796 KB |
Output is correct |
57 |
Correct |
324 ms |
6960 KB |
Output is correct |
58 |
Correct |
305 ms |
6876 KB |
Output is correct |
59 |
Correct |
320 ms |
6960 KB |
Output is correct |
60 |
Correct |
316 ms |
6856 KB |
Output is correct |
61 |
Correct |
309 ms |
6832 KB |
Output is correct |
62 |
Correct |
284 ms |
6796 KB |
Output is correct |
63 |
Correct |
4 ms |
588 KB |
Output is correct |
64 |
Correct |
5 ms |
656 KB |
Output is correct |
65 |
Correct |
1 ms |
460 KB |
Output is correct |
66 |
Correct |
1 ms |
588 KB |
Output is correct |
67 |
Execution timed out |
1088 ms |
25276 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |