Submission #951249

# Submission time Handle Problem Language Result Execution time Memory
951249 2024-03-21T13:40:33 Z NourWael Relay Marathon (NOI20_relaymarathon) C++17
17 / 100
1040 ms 13640 KB
#include <bits/stdc++.h>
#define int long long
using namespace std; 
int const mxN = 1e3+5;
vector<pair<int,int>> adj[mxN];
vector<int> spe;
bool is[mxN], vis[mxN];
int dist[mxN][mxN], cur[mxN];
int n; 
vector<pair<int,int>> lis[mxN];

void solve ( int i , int e1, int e2, bool f) {

   memset(vis,0,sizeof vis);
   for(int j=1; j<=n; j++) cur[j] = 1e18;
   priority_queue<pair<int,int>> q;
   q.push({0,i});
   
   while(q.size()) {
     int node = q.top().second, d = -(q.top().first);
     q.pop();
     if(vis[node]) continue;
     vis[node] = 1;
     for(auto it:adj[node]) {
      if(cur[it.first]<=d+it.second) continue;
      cur[it.first] = d+it.second;
      q.push({-(d+it.second), it.first});
     }
   }

   for(int j=1; j<=n; j++) { 
      dist[i][j] = cur[j];
      if(is[j] && is[i]) lis[i].push_back({dist[i][j],j});
   }
   sort(lis[i].begin(),lis[i].end());
}
signed main() {
  
  ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
   int m,k; cin>>n>>m>>k;
   for(int i=0; i<m; i++) {
      int x,y,c; cin>>x>>y>>c;
      adj[x].push_back({y,c}), adj[y].push_back({x,c});
   }
   
   for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dist[i][j] = 1e18; 
   for(int i=0; i<k; i++) {
      int x; cin>>x;
      is[x] = 1;
      spe.push_back(x);
   }
   
   for(int i=1; i<=n; i++) solve(i, 0, 0, 0);
    
   int ans = 1e18;

   for(int i=1; i<=n; i++) {
      if(!is[i]) continue;
      for(int j=1; j<=n; j++) {
         if(!is[j] || j==i) continue;
         for(int h=1; h<=n; h++) {
            if(!is[h] || h==i || h==j) continue;
            for(int ind=0; ind<min(5ll,(int)lis[h].size()); ind++) {
             if(lis[h][ind].second!=i && lis[h][ind].second!=j && lis[h][ind].second!=h &&  lis[h][ind].first+dist[i][j]<ans){
               ans =  lis[h][ind].first+dist[i][j];
             }
            }
         }
      }
   }

   cout<<ans;
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2904 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 3 ms 2652 KB Output is correct
18 Correct 1 ms 2904 KB Output is correct
19 Correct 3 ms 2648 KB Output is correct
20 Correct 2 ms 2904 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 3 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2904 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 3 ms 2652 KB Output is correct
18 Correct 1 ms 2904 KB Output is correct
19 Correct 3 ms 2648 KB Output is correct
20 Correct 2 ms 2904 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 3 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 7 ms 4700 KB Output is correct
32 Correct 17 ms 4788 KB Output is correct
33 Correct 22 ms 4700 KB Output is correct
34 Correct 4 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 345 ms 7176 KB Output is correct
37 Correct 1040 ms 9040 KB Output is correct
38 Correct 29 ms 4696 KB Output is correct
39 Correct 221 ms 10236 KB Output is correct
40 Correct 349 ms 8024 KB Output is correct
41 Correct 30 ms 4700 KB Output is correct
42 Correct 607 ms 8752 KB Output is correct
43 Correct 302 ms 7256 KB Output is correct
44 Correct 29 ms 4700 KB Output is correct
45 Correct 2 ms 4696 KB Output is correct
46 Correct 804 ms 13640 KB Output is correct
47 Correct 361 ms 7712 KB Output is correct
48 Correct 220 ms 10172 KB Output is correct
49 Correct 447 ms 12360 KB Output is correct
50 Correct 23 ms 4696 KB Output is correct
51 Correct 392 ms 7376 KB Output is correct
52 Correct 22 ms 4700 KB Output is correct
53 Correct 189 ms 7632 KB Output is correct
54 Correct 233 ms 10584 KB Output is correct
55 Correct 16 ms 4700 KB Output is correct
56 Correct 4 ms 4700 KB Output is correct
57 Correct 21 ms 4700 KB Output is correct
58 Correct 322 ms 11044 KB Output is correct
59 Correct 1 ms 4700 KB Output is correct
60 Correct 397 ms 7444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2904 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 3 ms 2652 KB Output is correct
18 Correct 1 ms 2904 KB Output is correct
19 Correct 3 ms 2648 KB Output is correct
20 Correct 2 ms 2904 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 3 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 7 ms 4700 KB Output is correct
32 Correct 17 ms 4788 KB Output is correct
33 Correct 22 ms 4700 KB Output is correct
34 Correct 4 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 345 ms 7176 KB Output is correct
37 Correct 1040 ms 9040 KB Output is correct
38 Correct 29 ms 4696 KB Output is correct
39 Correct 221 ms 10236 KB Output is correct
40 Correct 349 ms 8024 KB Output is correct
41 Correct 30 ms 4700 KB Output is correct
42 Correct 607 ms 8752 KB Output is correct
43 Correct 302 ms 7256 KB Output is correct
44 Correct 29 ms 4700 KB Output is correct
45 Correct 2 ms 4696 KB Output is correct
46 Correct 804 ms 13640 KB Output is correct
47 Correct 361 ms 7712 KB Output is correct
48 Correct 220 ms 10172 KB Output is correct
49 Correct 447 ms 12360 KB Output is correct
50 Correct 23 ms 4696 KB Output is correct
51 Correct 392 ms 7376 KB Output is correct
52 Correct 22 ms 4700 KB Output is correct
53 Correct 189 ms 7632 KB Output is correct
54 Correct 233 ms 10584 KB Output is correct
55 Correct 16 ms 4700 KB Output is correct
56 Correct 4 ms 4700 KB Output is correct
57 Correct 21 ms 4700 KB Output is correct
58 Correct 322 ms 11044 KB Output is correct
59 Correct 1 ms 4700 KB Output is correct
60 Correct 397 ms 7444 KB Output is correct
61 Runtime error 1 ms 604 KB Execution killed with signal 11
62 Halted 0 ms 0 KB -