답안 #820293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
820293 2023-08-11T03:53:40 Z damwuan 자매 도시 (APIO20_swap) C++17
53 / 100
203 ms 42652 KB



#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
//#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=2e5+69;
const ll offset=1e9;
const ll block_sz=317;
const ll inf=1e18;
const ll mod=1e9+7;
int n,par[maxn],m,deg[maxn],val[maxn],up[maxn][20],in[maxn],out[maxn],Time,ans[maxn];
bool ok[maxn];
vector<int> adj[maxn];
pair<int,pii> Edge[maxn];
map<pii,int> L;
int Find(int u)
{
    return (par[u]<0?u:par[u]=Find(par[u]));
}
void AddEdge(int u,int v,int w)
{
    val[n]=w;
    deg[u]++;
    deg[v]++;
    if (deg[u]>2 || deg[v]>2) ok[n]=1;
    u=Find(u);
    v=Find(v);
    par[n]+=par[u];
    par[u]=n;
    adj[n].pb(u);
    if (u!=v)
    {
        adj[n].pb(v);
        par[n]+=par[v];
        par[v]=n;
    }
    ok[n]=ok[n]|ok[u]|ok[v];
    //cerr<<n<<' '<<ok[n]<<' '<<val[n]<< " kk\n";
    n++;
}
void dfs(int u,int pre)
{
    in[u]=++Time;
    up[u][0]=pre;
    for1(i,1,19)
    {
        up[u][i]=up[up[u][i-1]][i-1];
    }
    if (ok[u]||adj[u].size()==1) ans[u]=val[u];
    else if (u!=pre) ans[u]=ans[pre];
    else ans[u]=-1;
    //cerr <<"acac "<<u<<' '<<ans[u]<<'\n';
    for(int v: adj[u])
    {
        dfs(v,u);
    }
    out[u]=Time;
}
bool is_ancestor(int u,int v)
{
    return (in[u]<=in[v] && out[v] <= out[u]);
}
int lca(int u,int v)
{
    if (is_ancestor(u,v)) return u;
    if (is_ancestor(v,u)) return v;
    for2(i,19,0)
    {
        if (!is_ancestor(up[u][i],v)) u=up[u][i];
    }
    return up[u][0];
}
void init(int N,int M,vector<int> U,vector<int> V, vector<int> W)
{
    n=N;
    m=M;
    for1(i,0,n+m) par[i]=-1;
    for1(i,0,m-1)
    {
        Edge[i+1]={W[i],{U[i],V[i]}};
        //L[{U[i],V[i]}]=W[i];
    }
    sort(Edge+1,Edge+1+m);
    for1(i,1,m)
    {
        AddEdge(Edge[i].se.fi,Edge[i].se.se,Edge[i].fi);
    }
    dfs(n-1,n-1);
}
int getMinimumFuelCapacity(int X, int Y) {
  return ans[lca(X,Y)];
}

//
//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 2 ms 4948 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5280 KB Output is correct
9 Correct 78 ms 27296 KB Output is correct
10 Correct 93 ms 32332 KB Output is correct
11 Correct 100 ms 31896 KB Output is correct
12 Correct 100 ms 33404 KB Output is correct
13 Correct 81 ms 35776 KB Output is correct
14 Correct 102 ms 27596 KB Output is correct
15 Correct 166 ms 36660 KB Output is correct
16 Correct 160 ms 35836 KB Output is correct
17 Correct 166 ms 37504 KB Output is correct
18 Correct 193 ms 39852 KB Output is correct
19 Correct 65 ms 14632 KB Output is correct
20 Correct 176 ms 37660 KB Output is correct
21 Correct 160 ms 36992 KB Output is correct
22 Correct 173 ms 38864 KB Output is correct
23 Correct 191 ms 41464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 167 ms 41144 KB Output is correct
4 Correct 189 ms 42652 KB Output is correct
5 Correct 174 ms 42072 KB Output is correct
6 Correct 187 ms 42448 KB Output is correct
7 Correct 186 ms 42372 KB Output is correct
8 Correct 175 ms 40936 KB Output is correct
9 Correct 192 ms 42040 KB Output is correct
10 Correct 168 ms 40668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5280 KB Output is correct
9 Correct 2 ms 5008 KB Output is correct
10 Correct 3 ms 5316 KB Output is correct
11 Correct 3 ms 5204 KB Output is correct
12 Correct 3 ms 5280 KB Output is correct
13 Correct 3 ms 5152 KB Output is correct
14 Correct 3 ms 5276 KB Output is correct
15 Correct 3 ms 5280 KB Output is correct
16 Correct 3 ms 5204 KB Output is correct
17 Correct 3 ms 5332 KB Output is correct
18 Correct 3 ms 5292 KB Output is correct
19 Correct 3 ms 5204 KB Output is correct
20 Correct 3 ms 5280 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 3 ms 5460 KB Output is correct
23 Correct 2 ms 5204 KB Output is correct
24 Correct 4 ms 5452 KB Output is correct
25 Correct 3 ms 5404 KB Output is correct
26 Correct 4 ms 5536 KB Output is correct
27 Correct 4 ms 5332 KB Output is correct
28 Correct 4 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5012 KB Output is correct
4 Correct 2 ms 5008 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5204 KB Output is correct
9 Correct 3 ms 5280 KB Output is correct
10 Correct 78 ms 27296 KB Output is correct
11 Correct 93 ms 32332 KB Output is correct
12 Correct 100 ms 31896 KB Output is correct
13 Correct 100 ms 33404 KB Output is correct
14 Correct 81 ms 35776 KB Output is correct
15 Correct 3 ms 5316 KB Output is correct
16 Correct 3 ms 5204 KB Output is correct
17 Correct 3 ms 5280 KB Output is correct
18 Correct 3 ms 5152 KB Output is correct
19 Correct 3 ms 5276 KB Output is correct
20 Correct 3 ms 5280 KB Output is correct
21 Correct 3 ms 5204 KB Output is correct
22 Correct 3 ms 5332 KB Output is correct
23 Correct 3 ms 5292 KB Output is correct
24 Correct 3 ms 5204 KB Output is correct
25 Correct 3 ms 5280 KB Output is correct
26 Correct 3 ms 5332 KB Output is correct
27 Correct 3 ms 5460 KB Output is correct
28 Correct 2 ms 5204 KB Output is correct
29 Correct 4 ms 5452 KB Output is correct
30 Correct 3 ms 5404 KB Output is correct
31 Correct 4 ms 5536 KB Output is correct
32 Correct 4 ms 5332 KB Output is correct
33 Correct 4 ms 5460 KB Output is correct
34 Correct 11 ms 8900 KB Output is correct
35 Correct 99 ms 33168 KB Output is correct
36 Correct 106 ms 33128 KB Output is correct
37 Correct 106 ms 33064 KB Output is correct
38 Correct 108 ms 32912 KB Output is correct
39 Correct 107 ms 32640 KB Output is correct
40 Correct 101 ms 30336 KB Output is correct
41 Correct 115 ms 33448 KB Output is correct
42 Correct 101 ms 33220 KB Output is correct
43 Correct 96 ms 36252 KB Output is correct
44 Correct 102 ms 33484 KB Output is correct
45 Runtime error 43 ms 20076 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5280 KB Output is correct
9 Correct 78 ms 27296 KB Output is correct
10 Correct 93 ms 32332 KB Output is correct
11 Correct 100 ms 31896 KB Output is correct
12 Correct 100 ms 33404 KB Output is correct
13 Correct 81 ms 35776 KB Output is correct
14 Correct 102 ms 27596 KB Output is correct
15 Correct 166 ms 36660 KB Output is correct
16 Correct 160 ms 35836 KB Output is correct
17 Correct 166 ms 37504 KB Output is correct
18 Correct 193 ms 39852 KB Output is correct
19 Correct 167 ms 41144 KB Output is correct
20 Correct 189 ms 42652 KB Output is correct
21 Correct 174 ms 42072 KB Output is correct
22 Correct 187 ms 42448 KB Output is correct
23 Correct 186 ms 42372 KB Output is correct
24 Correct 175 ms 40936 KB Output is correct
25 Correct 192 ms 42040 KB Output is correct
26 Correct 168 ms 40668 KB Output is correct
27 Correct 3 ms 5316 KB Output is correct
28 Correct 3 ms 5204 KB Output is correct
29 Correct 3 ms 5280 KB Output is correct
30 Correct 3 ms 5152 KB Output is correct
31 Correct 3 ms 5276 KB Output is correct
32 Correct 3 ms 5280 KB Output is correct
33 Correct 3 ms 5204 KB Output is correct
34 Correct 3 ms 5332 KB Output is correct
35 Correct 3 ms 5292 KB Output is correct
36 Correct 11 ms 8900 KB Output is correct
37 Correct 99 ms 33168 KB Output is correct
38 Correct 106 ms 33128 KB Output is correct
39 Correct 106 ms 33064 KB Output is correct
40 Correct 108 ms 32912 KB Output is correct
41 Correct 107 ms 32640 KB Output is correct
42 Correct 101 ms 30336 KB Output is correct
43 Correct 115 ms 33448 KB Output is correct
44 Correct 101 ms 33220 KB Output is correct
45 Correct 96 ms 36252 KB Output is correct
46 Correct 102 ms 33484 KB Output is correct
47 Correct 17 ms 8996 KB Output is correct
48 Correct 171 ms 38028 KB Output is correct
49 Correct 182 ms 37932 KB Output is correct
50 Correct 172 ms 37976 KB Output is correct
51 Correct 169 ms 37804 KB Output is correct
52 Correct 169 ms 36480 KB Output is correct
53 Correct 135 ms 29652 KB Output is correct
54 Correct 203 ms 38852 KB Output is correct
55 Correct 173 ms 38052 KB Output is correct
56 Correct 177 ms 40364 KB Output is correct
57 Correct 177 ms 38944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5012 KB Output is correct
4 Correct 2 ms 5008 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5204 KB Output is correct
9 Correct 3 ms 5280 KB Output is correct
10 Correct 78 ms 27296 KB Output is correct
11 Correct 93 ms 32332 KB Output is correct
12 Correct 100 ms 31896 KB Output is correct
13 Correct 100 ms 33404 KB Output is correct
14 Correct 81 ms 35776 KB Output is correct
15 Correct 102 ms 27596 KB Output is correct
16 Correct 166 ms 36660 KB Output is correct
17 Correct 160 ms 35836 KB Output is correct
18 Correct 166 ms 37504 KB Output is correct
19 Correct 193 ms 39852 KB Output is correct
20 Correct 167 ms 41144 KB Output is correct
21 Correct 189 ms 42652 KB Output is correct
22 Correct 174 ms 42072 KB Output is correct
23 Correct 187 ms 42448 KB Output is correct
24 Correct 186 ms 42372 KB Output is correct
25 Correct 175 ms 40936 KB Output is correct
26 Correct 192 ms 42040 KB Output is correct
27 Correct 168 ms 40668 KB Output is correct
28 Correct 3 ms 5316 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5280 KB Output is correct
31 Correct 3 ms 5152 KB Output is correct
32 Correct 3 ms 5276 KB Output is correct
33 Correct 3 ms 5280 KB Output is correct
34 Correct 3 ms 5204 KB Output is correct
35 Correct 3 ms 5332 KB Output is correct
36 Correct 3 ms 5292 KB Output is correct
37 Correct 11 ms 8900 KB Output is correct
38 Correct 99 ms 33168 KB Output is correct
39 Correct 106 ms 33128 KB Output is correct
40 Correct 106 ms 33064 KB Output is correct
41 Correct 108 ms 32912 KB Output is correct
42 Correct 107 ms 32640 KB Output is correct
43 Correct 101 ms 30336 KB Output is correct
44 Correct 115 ms 33448 KB Output is correct
45 Correct 101 ms 33220 KB Output is correct
46 Correct 96 ms 36252 KB Output is correct
47 Correct 102 ms 33484 KB Output is correct
48 Correct 17 ms 8996 KB Output is correct
49 Correct 171 ms 38028 KB Output is correct
50 Correct 182 ms 37932 KB Output is correct
51 Correct 172 ms 37976 KB Output is correct
52 Correct 169 ms 37804 KB Output is correct
53 Correct 169 ms 36480 KB Output is correct
54 Correct 135 ms 29652 KB Output is correct
55 Correct 203 ms 38852 KB Output is correct
56 Correct 173 ms 38052 KB Output is correct
57 Correct 177 ms 40364 KB Output is correct
58 Correct 177 ms 38944 KB Output is correct
59 Correct 65 ms 14632 KB Output is correct
60 Correct 176 ms 37660 KB Output is correct
61 Correct 160 ms 36992 KB Output is correct
62 Correct 173 ms 38864 KB Output is correct
63 Correct 191 ms 41464 KB Output is correct
64 Correct 3 ms 5204 KB Output is correct
65 Correct 3 ms 5280 KB Output is correct
66 Correct 3 ms 5332 KB Output is correct
67 Correct 3 ms 5460 KB Output is correct
68 Correct 2 ms 5204 KB Output is correct
69 Correct 4 ms 5452 KB Output is correct
70 Correct 3 ms 5404 KB Output is correct
71 Correct 4 ms 5536 KB Output is correct
72 Correct 4 ms 5332 KB Output is correct
73 Correct 4 ms 5460 KB Output is correct
74 Runtime error 43 ms 20076 KB Execution killed with signal 11
75 Halted 0 ms 0 KB -