#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+10;
int a[100001],d[100001],ch[100001],n,m,k,u,v,w,res=INF*2;
vector <pair <int, int>> ke[100001];
vector <int> ve[4];
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int f(int s, int e){
priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> q;
for (int i=1;i<=n;i++){
d[i]=INF;
ch[i]=0;
}
for (int i:ve[s]){
d[i]=0;
q.push({0,i});
}
for (int i:ve[e])
ch[i]=1;
while (!q.empty()){
auto [du,u]=q.top();
q.pop();
if (ch[u])
return du;
if (du!=d[u])
continue;
for (auto [v,w]:ke[u])
if (d[v]>d[u]+w){
d[v]=d[u]+w;
q.push({d[v],v});
}
}
return INF;
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> m >> k;
while (m--){
cin >> u >> v >> w;
ke[u].push_back({v,w});
ke[v].push_back({u,w});
}
for (int i=1;i<=k;i++)
cin >> a[i];
chrono::milliseconds ms(1150);
chrono::time_point<chrono::system_clock> end=chrono::system_clock::now()+ms;
while (chrono::system_clock::now()<end){
shuffle(a+1,a+k+1,rd);
for (int i=0;i<4;i++)
ve[i].clear();
for (int i=1;i<=k;i++)
ve[rd()%4].push_back(a[i]);
res=min(res,f(0,1)+f(2,3));
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1141 ms |
2676 KB |
Output is correct |
2 |
Correct |
1133 ms |
2720 KB |
Output is correct |
3 |
Correct |
1120 ms |
2672 KB |
Output is correct |
4 |
Correct |
1131 ms |
2664 KB |
Output is correct |
5 |
Correct |
1145 ms |
2676 KB |
Output is correct |
6 |
Correct |
1137 ms |
2768 KB |
Output is correct |
7 |
Correct |
1139 ms |
2724 KB |
Output is correct |
8 |
Correct |
1136 ms |
2816 KB |
Output is correct |
9 |
Correct |
1139 ms |
2668 KB |
Output is correct |
10 |
Correct |
1139 ms |
2664 KB |
Output is correct |
11 |
Correct |
1142 ms |
2672 KB |
Output is correct |
12 |
Correct |
1143 ms |
2672 KB |
Output is correct |
13 |
Correct |
1140 ms |
2720 KB |
Output is correct |
14 |
Correct |
1134 ms |
2724 KB |
Output is correct |
15 |
Correct |
1146 ms |
2720 KB |
Output is correct |
16 |
Correct |
1143 ms |
2672 KB |
Output is correct |
17 |
Correct |
1149 ms |
2700 KB |
Output is correct |
18 |
Correct |
1147 ms |
2680 KB |
Output is correct |
19 |
Correct |
1150 ms |
2720 KB |
Output is correct |
20 |
Correct |
1147 ms |
2700 KB |
Output is correct |
21 |
Correct |
1144 ms |
2696 KB |
Output is correct |
22 |
Correct |
1144 ms |
2668 KB |
Output is correct |
23 |
Correct |
1144 ms |
2700 KB |
Output is correct |
24 |
Correct |
1150 ms |
2668 KB |
Output is correct |
25 |
Correct |
1146 ms |
2768 KB |
Output is correct |
26 |
Correct |
1143 ms |
2804 KB |
Output is correct |
27 |
Correct |
1151 ms |
2672 KB |
Output is correct |
28 |
Correct |
1144 ms |
2728 KB |
Output is correct |
29 |
Correct |
1139 ms |
2716 KB |
Output is correct |
30 |
Correct |
1134 ms |
2740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1141 ms |
2676 KB |
Output is correct |
2 |
Correct |
1133 ms |
2720 KB |
Output is correct |
3 |
Correct |
1120 ms |
2672 KB |
Output is correct |
4 |
Correct |
1131 ms |
2664 KB |
Output is correct |
5 |
Correct |
1145 ms |
2676 KB |
Output is correct |
6 |
Correct |
1137 ms |
2768 KB |
Output is correct |
7 |
Correct |
1139 ms |
2724 KB |
Output is correct |
8 |
Correct |
1136 ms |
2816 KB |
Output is correct |
9 |
Correct |
1139 ms |
2668 KB |
Output is correct |
10 |
Correct |
1139 ms |
2664 KB |
Output is correct |
11 |
Correct |
1142 ms |
2672 KB |
Output is correct |
12 |
Correct |
1143 ms |
2672 KB |
Output is correct |
13 |
Correct |
1140 ms |
2720 KB |
Output is correct |
14 |
Correct |
1134 ms |
2724 KB |
Output is correct |
15 |
Correct |
1146 ms |
2720 KB |
Output is correct |
16 |
Correct |
1143 ms |
2672 KB |
Output is correct |
17 |
Correct |
1149 ms |
2700 KB |
Output is correct |
18 |
Correct |
1147 ms |
2680 KB |
Output is correct |
19 |
Correct |
1150 ms |
2720 KB |
Output is correct |
20 |
Correct |
1147 ms |
2700 KB |
Output is correct |
21 |
Correct |
1144 ms |
2696 KB |
Output is correct |
22 |
Correct |
1144 ms |
2668 KB |
Output is correct |
23 |
Correct |
1144 ms |
2700 KB |
Output is correct |
24 |
Correct |
1150 ms |
2668 KB |
Output is correct |
25 |
Correct |
1146 ms |
2768 KB |
Output is correct |
26 |
Correct |
1143 ms |
2804 KB |
Output is correct |
27 |
Correct |
1151 ms |
2672 KB |
Output is correct |
28 |
Correct |
1144 ms |
2728 KB |
Output is correct |
29 |
Correct |
1139 ms |
2716 KB |
Output is correct |
30 |
Correct |
1134 ms |
2740 KB |
Output is correct |
31 |
Correct |
1140 ms |
2764 KB |
Output is correct |
32 |
Correct |
1146 ms |
2704 KB |
Output is correct |
33 |
Correct |
1144 ms |
2720 KB |
Output is correct |
34 |
Correct |
1139 ms |
2692 KB |
Output is correct |
35 |
Correct |
1150 ms |
2680 KB |
Output is correct |
36 |
Correct |
1152 ms |
2772 KB |
Output is correct |
37 |
Correct |
1151 ms |
3020 KB |
Output is correct |
38 |
Correct |
1148 ms |
2724 KB |
Output is correct |
39 |
Correct |
1157 ms |
5964 KB |
Output is correct |
40 |
Correct |
1155 ms |
3532 KB |
Output is correct |
41 |
Correct |
1148 ms |
2764 KB |
Output is correct |
42 |
Correct |
1154 ms |
3456 KB |
Output is correct |
43 |
Correct |
1151 ms |
2944 KB |
Output is correct |
44 |
Correct |
1146 ms |
2728 KB |
Output is correct |
45 |
Correct |
1151 ms |
2692 KB |
Output is correct |
46 |
Correct |
1168 ms |
6212 KB |
Output is correct |
47 |
Correct |
1147 ms |
3164 KB |
Output is correct |
48 |
Correct |
1163 ms |
5848 KB |
Output is correct |
49 |
Correct |
1160 ms |
5968 KB |
Output is correct |
50 |
Correct |
1136 ms |
2724 KB |
Output is correct |
51 |
Correct |
1134 ms |
2764 KB |
Output is correct |
52 |
Correct |
1145 ms |
2708 KB |
Output is correct |
53 |
Correct |
1158 ms |
4408 KB |
Output is correct |
54 |
Correct |
1164 ms |
5996 KB |
Output is correct |
55 |
Correct |
1143 ms |
2708 KB |
Output is correct |
56 |
Correct |
1149 ms |
2688 KB |
Output is correct |
57 |
Correct |
1138 ms |
2708 KB |
Output is correct |
58 |
Correct |
1172 ms |
6408 KB |
Output is correct |
59 |
Correct |
1144 ms |
2764 KB |
Output is correct |
60 |
Correct |
1144 ms |
2748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1178 ms |
7400 KB |
Output is correct |
2 |
Correct |
1142 ms |
4020 KB |
Output is correct |
3 |
Correct |
2116 ms |
103756 KB |
Output is correct |
4 |
Correct |
1546 ms |
48112 KB |
Output is correct |
5 |
Correct |
1219 ms |
12492 KB |
Output is correct |
6 |
Correct |
1188 ms |
10500 KB |
Output is correct |
7 |
Correct |
1228 ms |
13460 KB |
Output is correct |
8 |
Correct |
1184 ms |
7452 KB |
Output is correct |
9 |
Correct |
1184 ms |
9920 KB |
Output is correct |
10 |
Correct |
1181 ms |
8268 KB |
Output is correct |
11 |
Correct |
2220 ms |
108064 KB |
Output is correct |
12 |
Correct |
1171 ms |
8612 KB |
Output is correct |
13 |
Correct |
1402 ms |
31244 KB |
Output is correct |
14 |
Correct |
1216 ms |
13196 KB |
Output is correct |
15 |
Correct |
2174 ms |
106252 KB |
Output is correct |
16 |
Correct |
1173 ms |
6916 KB |
Output is correct |
17 |
Correct |
1836 ms |
73052 KB |
Output is correct |
18 |
Correct |
1139 ms |
4076 KB |
Output is correct |
19 |
Correct |
2199 ms |
107672 KB |
Output is correct |
20 |
Correct |
1225 ms |
12240 KB |
Output is correct |
21 |
Correct |
1221 ms |
11804 KB |
Output is correct |
22 |
Correct |
1182 ms |
8008 KB |
Output is correct |
23 |
Correct |
1157 ms |
6148 KB |
Output is correct |
24 |
Correct |
1831 ms |
84272 KB |
Output is correct |
25 |
Correct |
1206 ms |
10008 KB |
Output is correct |
26 |
Correct |
1164 ms |
7400 KB |
Output is correct |
27 |
Correct |
1192 ms |
8976 KB |
Output is correct |
28 |
Correct |
1155 ms |
5068 KB |
Output is correct |
29 |
Correct |
1220 ms |
13124 KB |
Output is correct |
30 |
Correct |
1328 ms |
22332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1141 ms |
2676 KB |
Output is correct |
2 |
Correct |
1133 ms |
2720 KB |
Output is correct |
3 |
Correct |
1120 ms |
2672 KB |
Output is correct |
4 |
Correct |
1131 ms |
2664 KB |
Output is correct |
5 |
Correct |
1145 ms |
2676 KB |
Output is correct |
6 |
Correct |
1137 ms |
2768 KB |
Output is correct |
7 |
Correct |
1139 ms |
2724 KB |
Output is correct |
8 |
Correct |
1136 ms |
2816 KB |
Output is correct |
9 |
Correct |
1139 ms |
2668 KB |
Output is correct |
10 |
Correct |
1139 ms |
2664 KB |
Output is correct |
11 |
Correct |
1142 ms |
2672 KB |
Output is correct |
12 |
Correct |
1143 ms |
2672 KB |
Output is correct |
13 |
Correct |
1140 ms |
2720 KB |
Output is correct |
14 |
Correct |
1134 ms |
2724 KB |
Output is correct |
15 |
Correct |
1146 ms |
2720 KB |
Output is correct |
16 |
Correct |
1143 ms |
2672 KB |
Output is correct |
17 |
Correct |
1149 ms |
2700 KB |
Output is correct |
18 |
Correct |
1147 ms |
2680 KB |
Output is correct |
19 |
Correct |
1150 ms |
2720 KB |
Output is correct |
20 |
Correct |
1147 ms |
2700 KB |
Output is correct |
21 |
Correct |
1144 ms |
2696 KB |
Output is correct |
22 |
Correct |
1144 ms |
2668 KB |
Output is correct |
23 |
Correct |
1144 ms |
2700 KB |
Output is correct |
24 |
Correct |
1150 ms |
2668 KB |
Output is correct |
25 |
Correct |
1146 ms |
2768 KB |
Output is correct |
26 |
Correct |
1143 ms |
2804 KB |
Output is correct |
27 |
Correct |
1151 ms |
2672 KB |
Output is correct |
28 |
Correct |
1144 ms |
2728 KB |
Output is correct |
29 |
Correct |
1139 ms |
2716 KB |
Output is correct |
30 |
Correct |
1134 ms |
2740 KB |
Output is correct |
31 |
Correct |
1140 ms |
2764 KB |
Output is correct |
32 |
Correct |
1146 ms |
2704 KB |
Output is correct |
33 |
Correct |
1144 ms |
2720 KB |
Output is correct |
34 |
Correct |
1139 ms |
2692 KB |
Output is correct |
35 |
Correct |
1150 ms |
2680 KB |
Output is correct |
36 |
Correct |
1152 ms |
2772 KB |
Output is correct |
37 |
Correct |
1151 ms |
3020 KB |
Output is correct |
38 |
Correct |
1148 ms |
2724 KB |
Output is correct |
39 |
Correct |
1157 ms |
5964 KB |
Output is correct |
40 |
Correct |
1155 ms |
3532 KB |
Output is correct |
41 |
Correct |
1148 ms |
2764 KB |
Output is correct |
42 |
Correct |
1154 ms |
3456 KB |
Output is correct |
43 |
Correct |
1151 ms |
2944 KB |
Output is correct |
44 |
Correct |
1146 ms |
2728 KB |
Output is correct |
45 |
Correct |
1151 ms |
2692 KB |
Output is correct |
46 |
Correct |
1168 ms |
6212 KB |
Output is correct |
47 |
Correct |
1147 ms |
3164 KB |
Output is correct |
48 |
Correct |
1163 ms |
5848 KB |
Output is correct |
49 |
Correct |
1160 ms |
5968 KB |
Output is correct |
50 |
Correct |
1136 ms |
2724 KB |
Output is correct |
51 |
Correct |
1134 ms |
2764 KB |
Output is correct |
52 |
Correct |
1145 ms |
2708 KB |
Output is correct |
53 |
Correct |
1158 ms |
4408 KB |
Output is correct |
54 |
Correct |
1164 ms |
5996 KB |
Output is correct |
55 |
Correct |
1143 ms |
2708 KB |
Output is correct |
56 |
Correct |
1149 ms |
2688 KB |
Output is correct |
57 |
Correct |
1138 ms |
2708 KB |
Output is correct |
58 |
Correct |
1172 ms |
6408 KB |
Output is correct |
59 |
Correct |
1144 ms |
2764 KB |
Output is correct |
60 |
Correct |
1144 ms |
2748 KB |
Output is correct |
61 |
Correct |
1178 ms |
7400 KB |
Output is correct |
62 |
Correct |
1142 ms |
4020 KB |
Output is correct |
63 |
Correct |
2116 ms |
103756 KB |
Output is correct |
64 |
Correct |
1546 ms |
48112 KB |
Output is correct |
65 |
Correct |
1219 ms |
12492 KB |
Output is correct |
66 |
Correct |
1188 ms |
10500 KB |
Output is correct |
67 |
Correct |
1228 ms |
13460 KB |
Output is correct |
68 |
Correct |
1184 ms |
7452 KB |
Output is correct |
69 |
Correct |
1184 ms |
9920 KB |
Output is correct |
70 |
Correct |
1181 ms |
8268 KB |
Output is correct |
71 |
Correct |
2220 ms |
108064 KB |
Output is correct |
72 |
Correct |
1171 ms |
8612 KB |
Output is correct |
73 |
Correct |
1402 ms |
31244 KB |
Output is correct |
74 |
Correct |
1216 ms |
13196 KB |
Output is correct |
75 |
Correct |
2174 ms |
106252 KB |
Output is correct |
76 |
Correct |
1173 ms |
6916 KB |
Output is correct |
77 |
Correct |
1836 ms |
73052 KB |
Output is correct |
78 |
Correct |
1139 ms |
4076 KB |
Output is correct |
79 |
Correct |
2199 ms |
107672 KB |
Output is correct |
80 |
Correct |
1225 ms |
12240 KB |
Output is correct |
81 |
Correct |
1221 ms |
11804 KB |
Output is correct |
82 |
Correct |
1182 ms |
8008 KB |
Output is correct |
83 |
Correct |
1157 ms |
6148 KB |
Output is correct |
84 |
Correct |
1831 ms |
84272 KB |
Output is correct |
85 |
Correct |
1206 ms |
10008 KB |
Output is correct |
86 |
Correct |
1164 ms |
7400 KB |
Output is correct |
87 |
Correct |
1192 ms |
8976 KB |
Output is correct |
88 |
Correct |
1155 ms |
5068 KB |
Output is correct |
89 |
Correct |
1220 ms |
13124 KB |
Output is correct |
90 |
Correct |
1328 ms |
22332 KB |
Output is correct |
91 |
Incorrect |
1214 ms |
9568 KB |
Output isn't correct |
92 |
Halted |
0 ms |
0 KB |
- |