답안 #735491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735491 2023-05-04T08:05:45 Z keisuke6 자매 도시 (APIO20_swap) C++14
37 / 100
2000 ms 19076 KB
#include "swap.h"
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <algorithm>
#include <cassert>
using namespace std;
int N,M;
vector<int> U,V,W,W_;
vector<tuple<int,int,int>> S = {};
struct Unionfind{
  vector<int> par, siz;
  //初期化
  Unionfind(int n) : par(n,-1) , siz(n,1) {}
  int root(int x) {
    if(par[x] == -1) return x;
    else return par[x] = root(par[x]);
  }
  bool issame(int x,int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y){
    x = root(x); y = root(y);
    if(x ==  y) return false;
    if(siz[x] < siz[y]) swap(x,y);
    par[y] =  x;
    siz[x] += siz[y];
    return  true;
  }
  int size(int x) {
    return siz[root(x)];
  }
};
void init(int NN, int MM,
          std::vector<int> UU, std::vector<int> VV, std::vector<int> WW) {
            N = NN;
            M = MM;
            U = UU;
            V = VV;
            W = WW;
            W_ = W;
            for(int i=0;i<M;i++){
              S.push_back({W[i],U[i],V[i]});
            }
            sort(S.begin(),S.end());
}
 
int getMinimumFuelCapacity(int X, int Y) {
  vector<int> E = {};
  vector<vector<int>> G(N);
  bool cone = false;
  Unionfind uf(N);
  for(int i=0;i<M;i++){
    int w,u,v;
    tie(w,u,v) = S[i];
    if(cone && uf.issame(u,v) && uf.issame(u,X)) return w;
    uf.unite(u,v);
    G[u].push_back(v);
    G[v].push_back(u);
    if(uf.issame(X,Y) && !cone){
      cone = true;
      vector<int> dist(N,1e9);
      dist[X] = 0;
      queue<int> q;
      q.push(X);
      while(!q.empty()){
        int pos = q.front();
        q.pop();
        for(int x:G[pos]){
          if(dist[x] != 1e9) continue;
          dist[x] = dist[pos] + 1;
          q.push(x);
          continue;
        }
      }
      int now = Y;
      while(dist[now]){
        E.push_back(now);
        for(int x:G[now]){
          if(dist[x]+1 == dist[now]){
            now = x;
            continue;
          }
        }
      }
      E.push_back(X);
      for(int x:E){
        if(G[x].size() >= 3) return w;
      }
    }
    if(cone){
      if((G[u].size() >= 3 && uf.issame(X,u)) || (G[v].size() >= 3 && uf.issame(X,v))) return w;
    }
  }
  return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 72 ms 8916 KB Output is correct
10 Correct 169 ms 10888 KB Output is correct
11 Correct 153 ms 11016 KB Output is correct
12 Correct 208 ms 11644 KB Output is correct
13 Correct 126 ms 11624 KB Output is correct
14 Execution timed out 2089 ms 9576 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 2054 ms 13372 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 436 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 72 ms 8916 KB Output is correct
11 Correct 169 ms 10888 KB Output is correct
12 Correct 153 ms 11016 KB Output is correct
13 Correct 208 ms 11644 KB Output is correct
14 Correct 126 ms 11624 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 436 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 8 ms 1940 KB Output is correct
35 Correct 191 ms 13188 KB Output is correct
36 Correct 165 ms 13160 KB Output is correct
37 Correct 203 ms 13064 KB Output is correct
38 Correct 180 ms 12584 KB Output is correct
39 Correct 164 ms 12484 KB Output is correct
40 Correct 138 ms 11464 KB Output is correct
41 Correct 177 ms 13452 KB Output is correct
42 Correct 174 ms 13256 KB Output is correct
43 Correct 110 ms 13032 KB Output is correct
44 Correct 175 ms 13304 KB Output is correct
45 Correct 139 ms 14496 KB Output is correct
46 Correct 180 ms 13076 KB Output is correct
47 Correct 202 ms 13068 KB Output is correct
48 Correct 147 ms 13480 KB Output is correct
49 Correct 58 ms 12444 KB Output is correct
50 Correct 50 ms 8988 KB Output is correct
51 Correct 104 ms 12348 KB Output is correct
52 Correct 173 ms 17068 KB Output is correct
53 Correct 170 ms 17948 KB Output is correct
54 Correct 213 ms 19076 KB Output is correct
55 Correct 121 ms 13608 KB Output is correct
56 Correct 202 ms 17320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 72 ms 8916 KB Output is correct
10 Correct 169 ms 10888 KB Output is correct
11 Correct 153 ms 11016 KB Output is correct
12 Correct 208 ms 11644 KB Output is correct
13 Correct 126 ms 11624 KB Output is correct
14 Execution timed out 2089 ms 9576 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 72 ms 8916 KB Output is correct
11 Correct 169 ms 10888 KB Output is correct
12 Correct 153 ms 11016 KB Output is correct
13 Correct 208 ms 11644 KB Output is correct
14 Correct 126 ms 11624 KB Output is correct
15 Execution timed out 2089 ms 9576 KB Time limit exceeded
16 Halted 0 ms 0 KB -