답안 #876969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876969 2023-11-22T15:29:24 Z 8pete8 자매 도시 (APIO20_swap) C++14
53 / 100
332 ms 76392 KB
#include "swap.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>  
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define ll long long    
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
const int mxn=3e5,lg=30;  
int pa[mxn+10],deg[mxn+10],val[mxn+10],up[mxn+10][lg+5],h[mxn+10];
bool yes[mxn+10];
vector<int>adj[mxn+10];
bitset<mxn+10>vis;
int find(int u){return ((pa[u]==u)?u:pa[u]=find(pa[u]));}
int cnt=0;
void merg(int a,int b){
  int u=find(a),v=find(b);
  cnt++;
  adj[cnt].pb(v);
  if(u==v){
    yes[cnt]=true;
    pa[v]=cnt;
    return;
  }
  adj[cnt].pb(u);
  yes[cnt]=(yes[v]||yes[u]);
  deg[a]++,deg[b]++;
  if(deg[a]>=3||deg[b]>=3)yes[cnt]=true;
  pa[u]=pa[v]=cnt;
}
void dfs(int cur){
  if(vis[cur])return;
  vis[cur]=true;
  for(auto i:adj[cur])h[i]=h[cur]+1,up[i][0]=cur,dfs(i);
}
void init(int n,int m,vector<int>u,vector<int>v,vector<int>w){
  cnt=n-1;
  for(int i=0;i<mxn;i++)pa[i]=i;
  vector<ppii>e;
  for(int i=0;i<m;i++)e.pb({w[i],{u[i],v[i]}});
  sort(all(e));
  for(auto i:e)merg(i.s.f,i.s.s),val[cnt]=i.f;
  for(int i=0;i<=cnt;i++)up[cnt][i]=cnt;
  dfs(cnt);
  for(int j=1;j<=lg;j++)for(int i=0;i<=cnt;i++)up[i][j]=up[up[i][j-1]][j-1];
}
int lca(int a,int b){
  if(h[a]<h[b])swap(a,b);
  int k=h[a]-h[b];
  for(int i=0;i<=lg;i++)if(k&(1<<i))a=up[a][i];
  if(a==b)return a;
  for(int i=lg;i>=0;i--)if((up[a][i]!=up[b][i]))a=up[a][i],b=up[b][i];
  return up[a][0];
}
int getMinimumFuelCapacity(int a,int b){
  int node=lca(a,b);
  for(int i=lg;i>=0;i--)if(!yes[up[node][i]]&&up[node][i])node=up[node][i];
  if(!yes[node])node=up[node][0];
  if(yes[node])return val[node];
  else return -1;
}/*
int main() {
  int N, M;
  assert(2 == scanf("%d %d", &N, &M));
  std::vector<int> U(M), V(M), W(M);
  for (int i = 0; i < M; ++i) {
    assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
  }
  int Q;
  assert(1 == scanf("%d", &Q));
  std::vector<int> X(Q), Y(Q);
  for (int i = 0; i < Q; ++i) {
    assert(2 == scanf("%d %d", &X[i], &Y[i]));
  }
  init(N, M, U, V, W);
  std::vector<int> minimum_fuel_capacities(Q);
  for (int i = 0; i < Q; ++i) {
    minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
  }

  for (int i = 0; i < Q; ++i) {
    printf("%d\n", minimum_fuel_capacities[i]);
  }
  
  return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 3 ms 13916 KB Output is correct
5 Correct 3 ms 13916 KB Output is correct
6 Correct 4 ms 13916 KB Output is correct
7 Correct 4 ms 13916 KB Output is correct
8 Correct 4 ms 14172 KB Output is correct
9 Correct 81 ms 40644 KB Output is correct
10 Correct 96 ms 48328 KB Output is correct
11 Correct 98 ms 48228 KB Output is correct
12 Correct 100 ms 48640 KB Output is correct
13 Correct 104 ms 51908 KB Output is correct
14 Correct 87 ms 41156 KB Output is correct
15 Correct 242 ms 50884 KB Output is correct
16 Correct 228 ms 48688 KB Output is correct
17 Correct 238 ms 51512 KB Output is correct
18 Correct 293 ms 54472 KB Output is correct
19 Correct 78 ms 23680 KB Output is correct
20 Correct 213 ms 51112 KB Output is correct
21 Correct 219 ms 51256 KB Output is correct
22 Correct 224 ms 53652 KB Output is correct
23 Correct 332 ms 56868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 274 ms 56836 KB Output is correct
4 Correct 245 ms 58932 KB Output is correct
5 Correct 300 ms 59260 KB Output is correct
6 Correct 263 ms 59000 KB Output is correct
7 Correct 263 ms 59160 KB Output is correct
8 Correct 250 ms 56528 KB Output is correct
9 Correct 277 ms 58940 KB Output is correct
10 Correct 252 ms 56420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 3 ms 13916 KB Output is correct
5 Correct 3 ms 13916 KB Output is correct
6 Correct 4 ms 13916 KB Output is correct
7 Correct 4 ms 13916 KB Output is correct
8 Correct 4 ms 14172 KB Output is correct
9 Correct 3 ms 13916 KB Output is correct
10 Correct 4 ms 14172 KB Output is correct
11 Correct 3 ms 13916 KB Output is correct
12 Correct 3 ms 13932 KB Output is correct
13 Correct 4 ms 13916 KB Output is correct
14 Correct 3 ms 13892 KB Output is correct
15 Correct 3 ms 13940 KB Output is correct
16 Correct 4 ms 13916 KB Output is correct
17 Correct 3 ms 14172 KB Output is correct
18 Correct 3 ms 13924 KB Output is correct
19 Correct 3 ms 14172 KB Output is correct
20 Correct 3 ms 13916 KB Output is correct
21 Correct 3 ms 14172 KB Output is correct
22 Correct 4 ms 14180 KB Output is correct
23 Correct 3 ms 13916 KB Output is correct
24 Correct 4 ms 14172 KB Output is correct
25 Correct 5 ms 14176 KB Output is correct
26 Correct 4 ms 14172 KB Output is correct
27 Correct 3 ms 14172 KB Output is correct
28 Correct 4 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 3 ms 13916 KB Output is correct
5 Correct 3 ms 13916 KB Output is correct
6 Correct 3 ms 13916 KB Output is correct
7 Correct 4 ms 13916 KB Output is correct
8 Correct 4 ms 13916 KB Output is correct
9 Correct 4 ms 14172 KB Output is correct
10 Correct 81 ms 40644 KB Output is correct
11 Correct 96 ms 48328 KB Output is correct
12 Correct 98 ms 48228 KB Output is correct
13 Correct 100 ms 48640 KB Output is correct
14 Correct 104 ms 51908 KB Output is correct
15 Correct 4 ms 14172 KB Output is correct
16 Correct 3 ms 13916 KB Output is correct
17 Correct 3 ms 13932 KB Output is correct
18 Correct 4 ms 13916 KB Output is correct
19 Correct 3 ms 13892 KB Output is correct
20 Correct 3 ms 13940 KB Output is correct
21 Correct 4 ms 13916 KB Output is correct
22 Correct 3 ms 14172 KB Output is correct
23 Correct 3 ms 13924 KB Output is correct
24 Correct 3 ms 14172 KB Output is correct
25 Correct 3 ms 13916 KB Output is correct
26 Correct 3 ms 14172 KB Output is correct
27 Correct 4 ms 14180 KB Output is correct
28 Correct 3 ms 13916 KB Output is correct
29 Correct 4 ms 14172 KB Output is correct
30 Correct 5 ms 14176 KB Output is correct
31 Correct 4 ms 14172 KB Output is correct
32 Correct 3 ms 14172 KB Output is correct
33 Correct 4 ms 14168 KB Output is correct
34 Correct 11 ms 17432 KB Output is correct
35 Correct 100 ms 49096 KB Output is correct
36 Correct 99 ms 49252 KB Output is correct
37 Correct 132 ms 49096 KB Output is correct
38 Correct 101 ms 49108 KB Output is correct
39 Correct 96 ms 48968 KB Output is correct
40 Correct 90 ms 46172 KB Output is correct
41 Correct 105 ms 49572 KB Output is correct
42 Correct 98 ms 49236 KB Output is correct
43 Correct 103 ms 53192 KB Output is correct
44 Correct 117 ms 49348 KB Output is correct
45 Correct 134 ms 63480 KB Output is correct
46 Correct 98 ms 49252 KB Output is correct
47 Correct 106 ms 49248 KB Output is correct
48 Correct 111 ms 54604 KB Output is correct
49 Correct 108 ms 57796 KB Output is correct
50 Correct 85 ms 47900 KB Output is correct
51 Correct 119 ms 57284 KB Output is correct
52 Correct 147 ms 69060 KB Output is correct
53 Correct 184 ms 72552 KB Output is correct
54 Incorrect 183 ms 76392 KB Output isn't correct
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 3 ms 13916 KB Output is correct
5 Correct 3 ms 13916 KB Output is correct
6 Correct 4 ms 13916 KB Output is correct
7 Correct 4 ms 13916 KB Output is correct
8 Correct 4 ms 14172 KB Output is correct
9 Correct 81 ms 40644 KB Output is correct
10 Correct 96 ms 48328 KB Output is correct
11 Correct 98 ms 48228 KB Output is correct
12 Correct 100 ms 48640 KB Output is correct
13 Correct 104 ms 51908 KB Output is correct
14 Correct 87 ms 41156 KB Output is correct
15 Correct 242 ms 50884 KB Output is correct
16 Correct 228 ms 48688 KB Output is correct
17 Correct 238 ms 51512 KB Output is correct
18 Correct 293 ms 54472 KB Output is correct
19 Correct 274 ms 56836 KB Output is correct
20 Correct 245 ms 58932 KB Output is correct
21 Correct 300 ms 59260 KB Output is correct
22 Correct 263 ms 59000 KB Output is correct
23 Correct 263 ms 59160 KB Output is correct
24 Correct 250 ms 56528 KB Output is correct
25 Correct 277 ms 58940 KB Output is correct
26 Correct 252 ms 56420 KB Output is correct
27 Correct 4 ms 14172 KB Output is correct
28 Correct 3 ms 13916 KB Output is correct
29 Correct 3 ms 13932 KB Output is correct
30 Correct 4 ms 13916 KB Output is correct
31 Correct 3 ms 13892 KB Output is correct
32 Correct 3 ms 13940 KB Output is correct
33 Correct 4 ms 13916 KB Output is correct
34 Correct 3 ms 14172 KB Output is correct
35 Correct 3 ms 13924 KB Output is correct
36 Correct 11 ms 17432 KB Output is correct
37 Correct 100 ms 49096 KB Output is correct
38 Correct 99 ms 49252 KB Output is correct
39 Correct 132 ms 49096 KB Output is correct
40 Correct 101 ms 49108 KB Output is correct
41 Correct 96 ms 48968 KB Output is correct
42 Correct 90 ms 46172 KB Output is correct
43 Correct 105 ms 49572 KB Output is correct
44 Correct 98 ms 49236 KB Output is correct
45 Correct 103 ms 53192 KB Output is correct
46 Correct 117 ms 49348 KB Output is correct
47 Correct 21 ms 17532 KB Output is correct
48 Correct 248 ms 52980 KB Output is correct
49 Correct 224 ms 52956 KB Output is correct
50 Correct 231 ms 52936 KB Output is correct
51 Correct 217 ms 52972 KB Output is correct
52 Correct 224 ms 50468 KB Output is correct
53 Correct 182 ms 43684 KB Output is correct
54 Correct 211 ms 53676 KB Output is correct
55 Correct 213 ms 53028 KB Output is correct
56 Correct 294 ms 56264 KB Output is correct
57 Correct 268 ms 53716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 3 ms 13916 KB Output is correct
5 Correct 3 ms 13916 KB Output is correct
6 Correct 3 ms 13916 KB Output is correct
7 Correct 4 ms 13916 KB Output is correct
8 Correct 4 ms 13916 KB Output is correct
9 Correct 4 ms 14172 KB Output is correct
10 Correct 81 ms 40644 KB Output is correct
11 Correct 96 ms 48328 KB Output is correct
12 Correct 98 ms 48228 KB Output is correct
13 Correct 100 ms 48640 KB Output is correct
14 Correct 104 ms 51908 KB Output is correct
15 Correct 87 ms 41156 KB Output is correct
16 Correct 242 ms 50884 KB Output is correct
17 Correct 228 ms 48688 KB Output is correct
18 Correct 238 ms 51512 KB Output is correct
19 Correct 293 ms 54472 KB Output is correct
20 Correct 274 ms 56836 KB Output is correct
21 Correct 245 ms 58932 KB Output is correct
22 Correct 300 ms 59260 KB Output is correct
23 Correct 263 ms 59000 KB Output is correct
24 Correct 263 ms 59160 KB Output is correct
25 Correct 250 ms 56528 KB Output is correct
26 Correct 277 ms 58940 KB Output is correct
27 Correct 252 ms 56420 KB Output is correct
28 Correct 4 ms 14172 KB Output is correct
29 Correct 3 ms 13916 KB Output is correct
30 Correct 3 ms 13932 KB Output is correct
31 Correct 4 ms 13916 KB Output is correct
32 Correct 3 ms 13892 KB Output is correct
33 Correct 3 ms 13940 KB Output is correct
34 Correct 4 ms 13916 KB Output is correct
35 Correct 3 ms 14172 KB Output is correct
36 Correct 3 ms 13924 KB Output is correct
37 Correct 11 ms 17432 KB Output is correct
38 Correct 100 ms 49096 KB Output is correct
39 Correct 99 ms 49252 KB Output is correct
40 Correct 132 ms 49096 KB Output is correct
41 Correct 101 ms 49108 KB Output is correct
42 Correct 96 ms 48968 KB Output is correct
43 Correct 90 ms 46172 KB Output is correct
44 Correct 105 ms 49572 KB Output is correct
45 Correct 98 ms 49236 KB Output is correct
46 Correct 103 ms 53192 KB Output is correct
47 Correct 117 ms 49348 KB Output is correct
48 Correct 21 ms 17532 KB Output is correct
49 Correct 248 ms 52980 KB Output is correct
50 Correct 224 ms 52956 KB Output is correct
51 Correct 231 ms 52936 KB Output is correct
52 Correct 217 ms 52972 KB Output is correct
53 Correct 224 ms 50468 KB Output is correct
54 Correct 182 ms 43684 KB Output is correct
55 Correct 211 ms 53676 KB Output is correct
56 Correct 213 ms 53028 KB Output is correct
57 Correct 294 ms 56264 KB Output is correct
58 Correct 268 ms 53716 KB Output is correct
59 Correct 78 ms 23680 KB Output is correct
60 Correct 213 ms 51112 KB Output is correct
61 Correct 219 ms 51256 KB Output is correct
62 Correct 224 ms 53652 KB Output is correct
63 Correct 332 ms 56868 KB Output is correct
64 Correct 3 ms 14172 KB Output is correct
65 Correct 3 ms 13916 KB Output is correct
66 Correct 3 ms 14172 KB Output is correct
67 Correct 4 ms 14180 KB Output is correct
68 Correct 3 ms 13916 KB Output is correct
69 Correct 4 ms 14172 KB Output is correct
70 Correct 5 ms 14176 KB Output is correct
71 Correct 4 ms 14172 KB Output is correct
72 Correct 3 ms 14172 KB Output is correct
73 Correct 4 ms 14168 KB Output is correct
74 Correct 134 ms 63480 KB Output is correct
75 Correct 98 ms 49252 KB Output is correct
76 Correct 106 ms 49248 KB Output is correct
77 Correct 111 ms 54604 KB Output is correct
78 Correct 108 ms 57796 KB Output is correct
79 Correct 85 ms 47900 KB Output is correct
80 Correct 119 ms 57284 KB Output is correct
81 Correct 147 ms 69060 KB Output is correct
82 Correct 184 ms 72552 KB Output is correct
83 Incorrect 183 ms 76392 KB Output isn't correct
84 Halted 0 ms 0 KB -