답안 #1081298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081298 2024-08-29T21:20:06 Z alexdd 자매 도시 (APIO20_swap) C++17
100 / 100
123 ms 22700 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
int father[100005],siz[100005],cap1[100005],cap2[100005],primu[100005],insus[100005],parent[100005];
int gas(int x)
{
    if(father[x]!=x)
        father[x]=gas(father[x]);
    return father[x];
}
void unite(int x, int y, int t)
{
    int rootx = gas(x), rooty = gas(y);
    if(rootx==rooty)
    {
        primu[rootx] = min(primu[rootx], t);
        return;
    }
    if(siz[rootx] < siz[rooty])
    {
        swap(rootx,rooty);
        swap(x,y);
    }
    insus[rooty]=t;
    father[rooty]=rootx;
    parent[rooty]=rootx;
    siz[rootx]+=siz[rooty];

    if(primu[rootx]!=INF)
    {

    }
    else if(primu[rooty]!=INF)
    {
        primu[rootx]=t;
    }
    else if(x==cap1[rootx] && y==cap1[rooty])
    {
        cap1[rootx]=cap2[rooty];
    }
    else if(x==cap1[rootx] && y==cap2[rooty])
    {
        cap1[rootx]=cap1[rooty];
    }
    else if(x==cap2[rootx] && y==cap1[rooty])
    {
        cap2[rootx]=cap2[rooty];
    }
    else if(x==cap2[rootx] && y==cap2[rooty])
    {
        cap2[rootx]=cap1[rooty];
    }
    else
    {
        primu[rootx]=t;
    }
}

vector<pair<int,pair<int,int>>> edges;
vector<int> con[100005];
int tin[100005],tout[100005],timer;
int depth[100005];
void dfs(int nod)
{
    tin[nod]=++timer;
    for(auto adj:con[nod])
    {
        depth[adj]=depth[nod]+1;
        dfs(adj);
    }
    tout[nod]=++timer;
}
bool isanc(int x, int y)
{
    return (tin[x]<=tin[y] && tout[x]>=tout[y]);
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    for(int i=0;i<M;i++)
        edges.push_back({W[i],{U[i],V[i]}});
    sort(edges.begin(),edges.end());
    for(int i=0;i<N;i++)
    {
        parent[i]=-1;
        father[i]=i;
        siz[i]=1;
        cap1[i]=cap2[i]=i;
        primu[i]=INF;
    }
    for(int i=0;i<edges.size();i++)
    {
        unite(edges[i].second.first, edges[i].second.second, edges[i].first);
    }
    for(int i=0;i<N;i++)
        if(parent[i]!=-1)
            con[parent[i]].push_back(i);
    for(int i=0;i<N;i++)
        if(parent[i]==-1)
            dfs(i);
}

int getMinimumFuelCapacity(int x, int y)
{
    int mnm=INF,aux=0;
    while(x!=-1 && !isanc(x,y))
    {
        aux = max(aux, insus[x]);
        x = parent[x];
    }
    if(x==-1)
        return -1;
    while(y!=x)
    {
        aux = max(aux, insus[y]);
        y = parent[y];
    }
    while(x!=-1)
    {
        mnm = min(mnm, max(aux, primu[x]));
        aux = max(aux, insus[x]);
        x = parent[x];
    }
    if(mnm==INF)
        return -1;
    else
        return mnm;
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=0;i<edges.size();i++)
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 33 ms 11112 KB Output is correct
10 Correct 44 ms 12996 KB Output is correct
11 Correct 39 ms 12996 KB Output is correct
12 Correct 44 ms 13512 KB Output is correct
13 Correct 34 ms 12996 KB Output is correct
14 Correct 42 ms 11756 KB Output is correct
15 Correct 95 ms 17108 KB Output is correct
16 Correct 92 ms 17016 KB Output is correct
17 Correct 91 ms 17592 KB Output is correct
18 Correct 76 ms 17128 KB Output is correct
19 Correct 44 ms 9488 KB Output is correct
20 Correct 85 ms 18200 KB Output is correct
21 Correct 91 ms 18432 KB Output is correct
22 Correct 94 ms 18992 KB Output is correct
23 Correct 86 ms 18632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 62 ms 17372 KB Output is correct
4 Correct 66 ms 17620 KB Output is correct
5 Correct 72 ms 18060 KB Output is correct
6 Correct 64 ms 17492 KB Output is correct
7 Correct 68 ms 17996 KB Output is correct
8 Correct 68 ms 17604 KB Output is correct
9 Correct 65 ms 17736 KB Output is correct
10 Correct 77 ms 17540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2648 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 2 ms 2812 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2832 KB Output is correct
20 Correct 2 ms 2904 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 2 ms 2908 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2856 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 33 ms 11112 KB Output is correct
11 Correct 44 ms 12996 KB Output is correct
12 Correct 39 ms 12996 KB Output is correct
13 Correct 44 ms 13512 KB Output is correct
14 Correct 34 ms 12996 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 2 ms 2812 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 1 ms 2832 KB Output is correct
25 Correct 2 ms 2904 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2856 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 2 ms 2860 KB Output is correct
34 Correct 7 ms 4188 KB Output is correct
35 Correct 39 ms 13112 KB Output is correct
36 Correct 40 ms 13176 KB Output is correct
37 Correct 42 ms 13256 KB Output is correct
38 Correct 47 ms 13156 KB Output is correct
39 Correct 42 ms 13012 KB Output is correct
40 Correct 38 ms 12148 KB Output is correct
41 Correct 44 ms 13512 KB Output is correct
42 Correct 45 ms 13260 KB Output is correct
43 Correct 32 ms 12740 KB Output is correct
44 Correct 38 ms 13256 KB Output is correct
45 Correct 49 ms 14816 KB Output is correct
46 Correct 38 ms 13256 KB Output is correct
47 Correct 39 ms 13252 KB Output is correct
48 Correct 40 ms 13508 KB Output is correct
49 Correct 41 ms 12484 KB Output is correct
50 Correct 37 ms 9584 KB Output is correct
51 Correct 42 ms 13000 KB Output is correct
52 Correct 74 ms 16836 KB Output is correct
53 Correct 61 ms 17856 KB Output is correct
54 Correct 68 ms 18696 KB Output is correct
55 Correct 30 ms 12580 KB Output is correct
56 Correct 65 ms 17348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 33 ms 11112 KB Output is correct
10 Correct 44 ms 12996 KB Output is correct
11 Correct 39 ms 12996 KB Output is correct
12 Correct 44 ms 13512 KB Output is correct
13 Correct 34 ms 12996 KB Output is correct
14 Correct 42 ms 11756 KB Output is correct
15 Correct 95 ms 17108 KB Output is correct
16 Correct 92 ms 17016 KB Output is correct
17 Correct 91 ms 17592 KB Output is correct
18 Correct 76 ms 17128 KB Output is correct
19 Correct 62 ms 17372 KB Output is correct
20 Correct 66 ms 17620 KB Output is correct
21 Correct 72 ms 18060 KB Output is correct
22 Correct 64 ms 17492 KB Output is correct
23 Correct 68 ms 17996 KB Output is correct
24 Correct 68 ms 17604 KB Output is correct
25 Correct 65 ms 17736 KB Output is correct
26 Correct 77 ms 17540 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 1 ms 2908 KB Output is correct
30 Correct 2 ms 2812 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 2 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 7 ms 4188 KB Output is correct
37 Correct 39 ms 13112 KB Output is correct
38 Correct 40 ms 13176 KB Output is correct
39 Correct 42 ms 13256 KB Output is correct
40 Correct 47 ms 13156 KB Output is correct
41 Correct 42 ms 13012 KB Output is correct
42 Correct 38 ms 12148 KB Output is correct
43 Correct 44 ms 13512 KB Output is correct
44 Correct 45 ms 13260 KB Output is correct
45 Correct 32 ms 12740 KB Output is correct
46 Correct 38 ms 13256 KB Output is correct
47 Correct 11 ms 4624 KB Output is correct
48 Correct 101 ms 18084 KB Output is correct
49 Correct 90 ms 18064 KB Output is correct
50 Correct 90 ms 17964 KB Output is correct
51 Correct 87 ms 17980 KB Output is correct
52 Correct 82 ms 17536 KB Output is correct
53 Correct 77 ms 15544 KB Output is correct
54 Correct 100 ms 19244 KB Output is correct
55 Correct 93 ms 17968 KB Output is correct
56 Correct 68 ms 17716 KB Output is correct
57 Correct 90 ms 18732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 33 ms 11112 KB Output is correct
11 Correct 44 ms 12996 KB Output is correct
12 Correct 39 ms 12996 KB Output is correct
13 Correct 44 ms 13512 KB Output is correct
14 Correct 34 ms 12996 KB Output is correct
15 Correct 42 ms 11756 KB Output is correct
16 Correct 95 ms 17108 KB Output is correct
17 Correct 92 ms 17016 KB Output is correct
18 Correct 91 ms 17592 KB Output is correct
19 Correct 76 ms 17128 KB Output is correct
20 Correct 62 ms 17372 KB Output is correct
21 Correct 66 ms 17620 KB Output is correct
22 Correct 72 ms 18060 KB Output is correct
23 Correct 64 ms 17492 KB Output is correct
24 Correct 68 ms 17996 KB Output is correct
25 Correct 68 ms 17604 KB Output is correct
26 Correct 65 ms 17736 KB Output is correct
27 Correct 77 ms 17540 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 2 ms 2812 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 2 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 7 ms 4188 KB Output is correct
38 Correct 39 ms 13112 KB Output is correct
39 Correct 40 ms 13176 KB Output is correct
40 Correct 42 ms 13256 KB Output is correct
41 Correct 47 ms 13156 KB Output is correct
42 Correct 42 ms 13012 KB Output is correct
43 Correct 38 ms 12148 KB Output is correct
44 Correct 44 ms 13512 KB Output is correct
45 Correct 45 ms 13260 KB Output is correct
46 Correct 32 ms 12740 KB Output is correct
47 Correct 38 ms 13256 KB Output is correct
48 Correct 11 ms 4624 KB Output is correct
49 Correct 101 ms 18084 KB Output is correct
50 Correct 90 ms 18064 KB Output is correct
51 Correct 90 ms 17964 KB Output is correct
52 Correct 87 ms 17980 KB Output is correct
53 Correct 82 ms 17536 KB Output is correct
54 Correct 77 ms 15544 KB Output is correct
55 Correct 100 ms 19244 KB Output is correct
56 Correct 93 ms 17968 KB Output is correct
57 Correct 68 ms 17716 KB Output is correct
58 Correct 90 ms 18732 KB Output is correct
59 Correct 44 ms 9488 KB Output is correct
60 Correct 85 ms 18200 KB Output is correct
61 Correct 91 ms 18432 KB Output is correct
62 Correct 94 ms 18992 KB Output is correct
63 Correct 86 ms 18632 KB Output is correct
64 Correct 1 ms 2832 KB Output is correct
65 Correct 2 ms 2904 KB Output is correct
66 Correct 2 ms 2908 KB Output is correct
67 Correct 2 ms 2908 KB Output is correct
68 Correct 2 ms 2908 KB Output is correct
69 Correct 2 ms 2908 KB Output is correct
70 Correct 2 ms 2856 KB Output is correct
71 Correct 2 ms 2908 KB Output is correct
72 Correct 2 ms 2908 KB Output is correct
73 Correct 2 ms 2860 KB Output is correct
74 Correct 49 ms 14816 KB Output is correct
75 Correct 38 ms 13256 KB Output is correct
76 Correct 39 ms 13252 KB Output is correct
77 Correct 40 ms 13508 KB Output is correct
78 Correct 41 ms 12484 KB Output is correct
79 Correct 37 ms 9584 KB Output is correct
80 Correct 42 ms 13000 KB Output is correct
81 Correct 74 ms 16836 KB Output is correct
82 Correct 61 ms 17856 KB Output is correct
83 Correct 68 ms 18696 KB Output is correct
84 Correct 30 ms 12580 KB Output is correct
85 Correct 65 ms 17348 KB Output is correct
86 Correct 29 ms 8064 KB Output is correct
87 Correct 92 ms 17924 KB Output is correct
88 Correct 89 ms 18128 KB Output is correct
89 Correct 82 ms 17892 KB Output is correct
90 Correct 88 ms 16068 KB Output is correct
91 Correct 94 ms 15760 KB Output is correct
92 Correct 85 ms 17960 KB Output is correct
93 Correct 113 ms 21620 KB Output is correct
94 Correct 110 ms 22432 KB Output is correct
95 Correct 123 ms 22700 KB Output is correct
96 Correct 82 ms 17712 KB Output is correct
97 Correct 99 ms 20304 KB Output is correct