답안 #951286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951286 2024-03-21T14:40:36 Z NourWael Relay Marathon (NOI20_relaymarathon) C++17
42 / 100
1069 ms 184936 KB
#include <bits/stdc++.h>
#define int long long
using namespace std; 
int const mxN = 1e5+5;
vector<pair<int,int>> adj[mxN];
vector<int> spe;
bool is[mxN], vis[mxN];
int dist[505][505], cur[mxN], come[mxN];
int n; 
vector<pair<int,int>> lis[mxN];

int solve () {

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

     if(vis[node]) continue;
     vis[node] = 1;

     for(auto it:adj[node]) {
      if(come[it.first]!=from) ans = min (ans, d+it.second+cur[it.first]);
      if(cur[it.first]<=d+it.second) continue;
      cur[it.first] = d+it.second;
      come[it.first] = from;
      q.push({-(d+it.second), {it.first,from}});
     }

   }

   return ans;
}

void solve2 ( 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=0; i<k; i++) {
      int x; cin>>x;
      is[x] = 1;
      if(x!=1 && x!=2 && n>500) spe.push_back(x);
   }
   
   if(n>500) cout<<solve()+1;
   else {
     for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dist[i][j] = 1e18; 
     for(int i=1; i<=n; i++) solve2(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;
}
/*
7 6 4
1 2 1
7 3 1
3 4 2
4 5 3
5 6 5
6 3 4
1 2 5 7
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8912 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 3 ms 8892 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8792 KB Output is correct
13 Correct 4 ms 8796 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 4 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 4 ms 8796 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 4 ms 9304 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8920 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 4 ms 9052 KB Output is correct
29 Correct 3 ms 8920 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8912 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 3 ms 8892 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8792 KB Output is correct
13 Correct 4 ms 8796 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 4 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 4 ms 8796 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 4 ms 9304 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8920 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 4 ms 9052 KB Output is correct
29 Correct 3 ms 8920 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 8 ms 8792 KB Output is correct
32 Correct 18 ms 8796 KB Output is correct
33 Correct 25 ms 8796 KB Output is correct
34 Correct 4 ms 8796 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 340 ms 11548 KB Output is correct
37 Correct 1054 ms 13188 KB Output is correct
38 Correct 30 ms 8796 KB Output is correct
39 Correct 222 ms 14320 KB Output is correct
40 Correct 351 ms 12124 KB Output is correct
41 Correct 30 ms 8796 KB Output is correct
42 Correct 578 ms 12848 KB Output is correct
43 Correct 298 ms 11348 KB Output is correct
44 Correct 29 ms 8796 KB Output is correct
45 Correct 3 ms 8792 KB Output is correct
46 Correct 791 ms 17488 KB Output is correct
47 Correct 354 ms 11856 KB Output is correct
48 Correct 207 ms 14168 KB Output is correct
49 Correct 411 ms 16212 KB Output is correct
50 Correct 24 ms 8796 KB Output is correct
51 Correct 381 ms 11600 KB Output is correct
52 Correct 25 ms 8796 KB Output is correct
53 Correct 173 ms 11768 KB Output is correct
54 Correct 219 ms 14172 KB Output is correct
55 Correct 19 ms 9052 KB Output is correct
56 Correct 5 ms 8792 KB Output is correct
57 Correct 22 ms 8796 KB Output is correct
58 Correct 315 ms 14904 KB Output is correct
59 Correct 3 ms 8796 KB Output is correct
60 Correct 401 ms 11600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 13916 KB Output is correct
2 Correct 4 ms 9308 KB Output is correct
3 Correct 1020 ms 164368 KB Output is correct
4 Correct 415 ms 81644 KB Output is correct
5 Correct 84 ms 22180 KB Output is correct
6 Correct 62 ms 18764 KB Output is correct
7 Correct 102 ms 23496 KB Output is correct
8 Correct 31 ms 14168 KB Output is correct
9 Correct 60 ms 17748 KB Output is correct
10 Correct 41 ms 15384 KB Output is correct
11 Correct 1063 ms 174920 KB Output is correct
12 Correct 45 ms 15952 KB Output is correct
13 Correct 273 ms 52768 KB Output is correct
14 Correct 98 ms 23796 KB Output is correct
15 Correct 1020 ms 172104 KB Output is correct
16 Correct 24 ms 13144 KB Output is correct
17 Correct 674 ms 125152 KB Output is correct
18 Correct 4 ms 9560 KB Output is correct
19 Correct 1069 ms 184936 KB Output is correct
20 Correct 111 ms 22844 KB Output is correct
21 Correct 90 ms 21076 KB Output is correct
22 Correct 39 ms 15124 KB Output is correct
23 Correct 14 ms 11868 KB Output is correct
24 Correct 717 ms 137164 KB Output is correct
25 Correct 58 ms 18000 KB Output is correct
26 Correct 32 ms 14100 KB Output is correct
27 Correct 49 ms 16720 KB Output is correct
28 Correct 8 ms 10588 KB Output is correct
29 Correct 94 ms 22984 KB Output is correct
30 Correct 227 ms 40488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8912 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 3 ms 8892 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8792 KB Output is correct
13 Correct 4 ms 8796 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 4 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 4 ms 8796 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 4 ms 9304 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8920 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 4 ms 9052 KB Output is correct
29 Correct 3 ms 8920 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 8 ms 8792 KB Output is correct
32 Correct 18 ms 8796 KB Output is correct
33 Correct 25 ms 8796 KB Output is correct
34 Correct 4 ms 8796 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 340 ms 11548 KB Output is correct
37 Correct 1054 ms 13188 KB Output is correct
38 Correct 30 ms 8796 KB Output is correct
39 Correct 222 ms 14320 KB Output is correct
40 Correct 351 ms 12124 KB Output is correct
41 Correct 30 ms 8796 KB Output is correct
42 Correct 578 ms 12848 KB Output is correct
43 Correct 298 ms 11348 KB Output is correct
44 Correct 29 ms 8796 KB Output is correct
45 Correct 3 ms 8792 KB Output is correct
46 Correct 791 ms 17488 KB Output is correct
47 Correct 354 ms 11856 KB Output is correct
48 Correct 207 ms 14168 KB Output is correct
49 Correct 411 ms 16212 KB Output is correct
50 Correct 24 ms 8796 KB Output is correct
51 Correct 381 ms 11600 KB Output is correct
52 Correct 25 ms 8796 KB Output is correct
53 Correct 173 ms 11768 KB Output is correct
54 Correct 219 ms 14172 KB Output is correct
55 Correct 19 ms 9052 KB Output is correct
56 Correct 5 ms 8792 KB Output is correct
57 Correct 22 ms 8796 KB Output is correct
58 Correct 315 ms 14904 KB Output is correct
59 Correct 3 ms 8796 KB Output is correct
60 Correct 401 ms 11600 KB Output is correct
61 Correct 32 ms 13916 KB Output is correct
62 Correct 4 ms 9308 KB Output is correct
63 Correct 1020 ms 164368 KB Output is correct
64 Correct 415 ms 81644 KB Output is correct
65 Correct 84 ms 22180 KB Output is correct
66 Correct 62 ms 18764 KB Output is correct
67 Correct 102 ms 23496 KB Output is correct
68 Correct 31 ms 14168 KB Output is correct
69 Correct 60 ms 17748 KB Output is correct
70 Correct 41 ms 15384 KB Output is correct
71 Correct 1063 ms 174920 KB Output is correct
72 Correct 45 ms 15952 KB Output is correct
73 Correct 273 ms 52768 KB Output is correct
74 Correct 98 ms 23796 KB Output is correct
75 Correct 1020 ms 172104 KB Output is correct
76 Correct 24 ms 13144 KB Output is correct
77 Correct 674 ms 125152 KB Output is correct
78 Correct 4 ms 9560 KB Output is correct
79 Correct 1069 ms 184936 KB Output is correct
80 Correct 111 ms 22844 KB Output is correct
81 Correct 90 ms 21076 KB Output is correct
82 Correct 39 ms 15124 KB Output is correct
83 Correct 14 ms 11868 KB Output is correct
84 Correct 717 ms 137164 KB Output is correct
85 Correct 58 ms 18000 KB Output is correct
86 Correct 32 ms 14100 KB Output is correct
87 Correct 49 ms 16720 KB Output is correct
88 Correct 8 ms 10588 KB Output is correct
89 Correct 94 ms 22984 KB Output is correct
90 Correct 227 ms 40488 KB Output is correct
91 Incorrect 62 ms 17416 KB Output isn't correct
92 Halted 0 ms 0 KB -