Submission #890108

# Submission time Handle Problem Language Result Execution time Memory
890108 2023-12-20T14:41:01 Z vjudge1 Relay Marathon (NOI20_relaymarathon) C++14
5 / 100
6000 ms 11512 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()

const int N=1e5+1, MAX_SIZE=4;
int n, m, k;
vector<pair<int, int>> dist[N];
vector<pair<int, int>> g[N];

bool optimize(int idx, pair<int, int> val){
   for (auto &i:dist[idx]) if (i.second==val.second){
      if (i.first>val.first){
         i=val;
         return 1;
      }
      return 0;
   }
   if ((int)dist[idx].size()<MAX_SIZE){
      dist[idx].push_back(val);
      sort(dist[idx].begin(), dist[idx].end());
      return 1;
   }
   if (val.first<dist[idx].back().first){
      dist[idx].push_back(val);
      sort(dist[idx].begin(), dist[idx].end());
      dist[idx].pop_back();
      return 1;
   }
   return 0;
}

bool optimize(int idx, int par, int w){
   bool ans=0;
   for (auto &i:dist[par]){
      ans|=optimize(idx, {i.first+w, i.second});
   }
   return ans;
}

struct cmp{
   bool operator()(const pair<vector<pair<int, int>>, int> &a, const pair<vector<pair<int, int>>, int> &b){
      for (int i=0; i<min<int>(a.first.size(), b.first.size()); ++i) if (a.first[i]!=b.first[i]) return a.first[i]<b.first[i];
      if (a.first.size()!=b.first.size()) return a.first.size()<b.first.size();
      return a.second<b.second;
   }
};

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n >> m >> k;
   // n=1e5; m=1e5; k=1e5;
   for (int i=1; i<=m; ++i){
      int u, v, w; cin >> u >> v >> w;
      // int u=i, v=i%n+1, w=1;
      g[u].emplace_back(v, w);
      g[v].emplace_back(u, w);
   }
   priority_queue<pair<vector<pair<int, int>>, int>, vector<pair<vector<pair<int, int>>, int>>, cmp> pq;
   for (int i=1; i<=k; ++i){
      int x; cin >> x;
      // int x=i;
      dist[x].emplace_back(0, x);
      pq.emplace(dist[x], x);
   }
   while (pq.size()){
      auto tt=pq.top().first;
      int u=pq.top().second; pq.pop();
      if (dist[u]!=tt) continue;
      for (auto &e:g[u]){
         int v=e.first, w=e.second;
         if (optimize(v, u, w)) pq.emplace(dist[v], v);
      }
   }
   int ans=1e18;
   set<pair<int, pair<int, int>>> st;
   for (int i=1; i<=n; ++i){
      vector<pair<int, int>> d2;
      for (auto &j:dist[i]){
         int u=i, v=j.second, d=j.first;
         if (d && find(all(dist[v]), pair<int, int>{d, u})!=dist[v].end()){
            st.insert({d, {min(u, v), max(u, v)}});
            d2.emplace_back(d, v);
         }
      }
      dist[i].swap(d2);
   }
   vector<pair<int, pair<int, int>>> v(all(st));
   v.resize(min((int)v.size(), (int)100));
   for (int i=0; i<(int)v.size(); ++i) for (int j=i+1; j<(int)v.size(); ++j){
      set<int> lmao;
      lmao.insert(v[i].second.first);
      lmao.insert(v[i].second.second);
      lmao.insert(v[j].second.first);
      lmao.insert(v[j].second.second);
      if ((int)lmao.size()==4) ans=min(ans, v[i].first+v[j].first);
   }
   cout << ans;
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 5212 KB Output is correct
14 Correct 2 ms 5224 KB Output is correct
15 Correct 2 ms 5212 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 5212 KB Output is correct
14 Correct 2 ms 5224 KB Output is correct
15 Correct 2 ms 5212 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5464 KB Output is correct
32 Correct 7 ms 5292 KB Output is correct
33 Correct 11 ms 5332 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 30 ms 7920 KB Output is correct
37 Correct 9 ms 6100 KB Output is correct
38 Correct 14 ms 5468 KB Output is correct
39 Correct 281 ms 10112 KB Output is correct
40 Correct 64 ms 8732 KB Output is correct
41 Correct 15 ms 5356 KB Output is correct
42 Correct 38 ms 8460 KB Output is correct
43 Correct 22 ms 7376 KB Output is correct
44 Incorrect 13 ms 5212 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6039 ms 11512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 5212 KB Output is correct
14 Correct 2 ms 5224 KB Output is correct
15 Correct 2 ms 5212 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5464 KB Output is correct
32 Correct 7 ms 5292 KB Output is correct
33 Correct 11 ms 5332 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 30 ms 7920 KB Output is correct
37 Correct 9 ms 6100 KB Output is correct
38 Correct 14 ms 5468 KB Output is correct
39 Correct 281 ms 10112 KB Output is correct
40 Correct 64 ms 8732 KB Output is correct
41 Correct 15 ms 5356 KB Output is correct
42 Correct 38 ms 8460 KB Output is correct
43 Correct 22 ms 7376 KB Output is correct
44 Incorrect 13 ms 5212 KB Output isn't correct
45 Halted 0 ms 0 KB -