답안 #890107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890107 2023-12-20T14:40:08 Z vjudge1 Relay Marathon (NOI20_relaymarathon) C++14
17 / 100
6000 ms 14336 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=6;
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 2 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 4 ms 5244 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 3 ms 5160 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 3 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 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 1 ms 4952 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 4 ms 5336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 2 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 4 ms 5244 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 3 ms 5160 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 3 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 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 1 ms 4952 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 4 ms 5336 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 8 ms 5300 KB Output is correct
33 Correct 10 ms 5208 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 46 ms 9496 KB Output is correct
37 Correct 15 ms 6872 KB Output is correct
38 Correct 17 ms 5468 KB Output is correct
39 Correct 500 ms 11120 KB Output is correct
40 Correct 95 ms 10272 KB Output is correct
41 Correct 19 ms 5464 KB Output is correct
42 Correct 81 ms 10536 KB Output is correct
43 Correct 32 ms 7952 KB Output is correct
44 Correct 16 ms 5212 KB Output is correct
45 Correct 1 ms 5152 KB Output is correct
46 Correct 249 ms 14336 KB Output is correct
47 Correct 84 ms 9924 KB Output is correct
48 Correct 438 ms 11468 KB Output is correct
49 Correct 335 ms 14276 KB Output is correct
50 Correct 13 ms 5208 KB Output is correct
51 Correct 6 ms 5464 KB Output is correct
52 Correct 12 ms 5212 KB Output is correct
53 Correct 322 ms 10240 KB Output is correct
54 Correct 511 ms 11292 KB Output is correct
55 Correct 12 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 12 ms 5212 KB Output is correct
58 Correct 581 ms 13104 KB Output is correct
59 Correct 1 ms 4956 KB Output is correct
60 Correct 10 ms 5980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6096 ms 12124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 2 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 4 ms 5244 KB Output is correct
8 Correct 4 ms 5212 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 3 ms 5160 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 3 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 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 1 ms 4952 KB Output is correct
28 Correct 3 ms 5212 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 4 ms 5336 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 8 ms 5300 KB Output is correct
33 Correct 10 ms 5208 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 46 ms 9496 KB Output is correct
37 Correct 15 ms 6872 KB Output is correct
38 Correct 17 ms 5468 KB Output is correct
39 Correct 500 ms 11120 KB Output is correct
40 Correct 95 ms 10272 KB Output is correct
41 Correct 19 ms 5464 KB Output is correct
42 Correct 81 ms 10536 KB Output is correct
43 Correct 32 ms 7952 KB Output is correct
44 Correct 16 ms 5212 KB Output is correct
45 Correct 1 ms 5152 KB Output is correct
46 Correct 249 ms 14336 KB Output is correct
47 Correct 84 ms 9924 KB Output is correct
48 Correct 438 ms 11468 KB Output is correct
49 Correct 335 ms 14276 KB Output is correct
50 Correct 13 ms 5208 KB Output is correct
51 Correct 6 ms 5464 KB Output is correct
52 Correct 12 ms 5212 KB Output is correct
53 Correct 322 ms 10240 KB Output is correct
54 Correct 511 ms 11292 KB Output is correct
55 Correct 12 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 12 ms 5212 KB Output is correct
58 Correct 581 ms 13104 KB Output is correct
59 Correct 1 ms 4956 KB Output is correct
60 Correct 10 ms 5980 KB Output is correct
61 Execution timed out 6096 ms 12124 KB Time limit exceeded
62 Halted 0 ms 0 KB -