Submission #347941

# Submission time Handle Problem Language Result Execution time Memory
347941 2021-01-13T21:25:21 Z MvC Swapping Cities (APIO20_swap) C++14
100 / 100
393 ms 44200 KB
#include "swap.h"
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=2e5+50;
const ll mod=1e9+7;
using namespace std;
int n,m,d[nmax],sz[nmax],p[nmax],gd[nmax],gud[nmax],x,y,rs,vl,mx[nmax],i,j;
vector<pair<int,pair<int,int> > >g;
vector<pair<int,int> >v[nmax];
vector<int>vc[nmax];
int fnd(int x)
{
    if(p[x]==x)return x;
    return p[x]=fnd(p[x]);
}
void uni(int x,int y,int z)
{
    d[x]++,d[y]++;
    int px=fnd(x),py=fnd(y),i;
    if(px==py)
    {
        if(!gd[px])
        {
            gd[px]=1;
            for(i=0;i<lun(vc[px]);i++)gud[vc[px][i]]=z;
        }
        return;
    }
    if(sz[px]<sz[py])
    {
        swap(px,py);
        swap(x,y);
    }
    p[py]=px;
    sz[px]+=sz[py];
    mx[px]=max(max(mx[px],mx[py]),max(d[x],d[y]));
    if(gd[px] && !gd[py])
    {
        for(i=0;i<lun(vc[py]);i++)gud[vc[py][i]]=z;
    }
    else if(!gd[px] && gd[py])
    {
        gd[px]=1;
        for(i=0;i<lun(vc[px]);i++)gud[vc[px][i]]=z;
    }
    for(i=0;i<lun(vc[py]);i++)
    {
        vc[px].pb(vc[py][i]);
        v[vc[py][i]].pb(mkp(px,z));
    }
    vc[py].clear();
    if(!gd[px] && !gd[py] && mx[px]>=3)
    {
        gd[px]=1;
        for(i=0;i<lun(vc[px]);i++)gud[vc[px][i]]=z;
    }
}
void init(int N,int M,vector<int> U,vector<int> V,vector<int> W)
{
    n=N,m=M;
    for(i=0;i<m;i++)
    {
        U[i]++,V[i]++;
        g.pb(mkp(W[i],mkp(U[i],V[i])));
    }
    sort(all(g));
    for(i=1;i<=n;i++)
    {
        sz[i]=1;
        p[i]=i;
        v[i].pb(mkp(i,0));
        vc[i].pb(i);
    }
    for(i=0;i<m;i++)
    {
        x=g[i].sc.fr,y=g[i].sc.sc;
        uni(x,y,g[i].fr);
    }
}
int getMinimumFuelCapacity(int x,int y)
{
    x++,y++,rs=inf;
    if(!gud[x])return -1;
    for(i=0;i<lun(v[x]);i++)
    {
        vl=inf;
        for(j=0;j<lun(v[y]);j++)
        {
            if(v[x][i].fr==v[y][j].fr)
            {
                vl=max(v[x][i].sc,v[y][j].sc);
                break;
            }
        }
        rs=min(rs,vl);
    }
    rs=max(rs,max(gud[x],gud[y]));
    return rs;
}
/*int main()
{
    //freopen("sol.in","r",stdin);
    //freopen("sol.out","w",stdout);
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);

    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 7 ms 9708 KB Output is correct
4 Correct 8 ms 9836 KB Output is correct
5 Correct 7 ms 9964 KB Output is correct
6 Correct 8 ms 9964 KB Output is correct
7 Correct 8 ms 9964 KB Output is correct
8 Correct 7 ms 9836 KB Output is correct
9 Correct 165 ms 27104 KB Output is correct
10 Correct 208 ms 30688 KB Output is correct
11 Correct 202 ms 30304 KB Output is correct
12 Correct 214 ms 31456 KB Output is correct
13 Correct 135 ms 23648 KB Output is correct
14 Correct 168 ms 27104 KB Output is correct
15 Correct 271 ms 32876 KB Output is correct
16 Correct 262 ms 32272 KB Output is correct
17 Correct 304 ms 33608 KB Output is correct
18 Correct 188 ms 25544 KB Output is correct
19 Correct 96 ms 16556 KB Output is correct
20 Correct 331 ms 34528 KB Output is correct
21 Correct 316 ms 33820 KB Output is correct
22 Correct 361 ms 35528 KB Output is correct
23 Correct 232 ms 27464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 183 ms 24452 KB Output is correct
4 Correct 192 ms 24776 KB Output is correct
5 Correct 194 ms 24824 KB Output is correct
6 Correct 186 ms 24776 KB Output is correct
7 Correct 190 ms 24928 KB Output is correct
8 Correct 187 ms 24464 KB Output is correct
9 Correct 187 ms 24672 KB Output is correct
10 Correct 192 ms 24348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 7 ms 9836 KB Output is correct
4 Correct 7 ms 9708 KB Output is correct
5 Correct 8 ms 9836 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 8 ms 9964 KB Output is correct
8 Correct 8 ms 9964 KB Output is correct
9 Correct 7 ms 9836 KB Output is correct
10 Correct 8 ms 9964 KB Output is correct
11 Correct 8 ms 9964 KB Output is correct
12 Correct 8 ms 9964 KB Output is correct
13 Correct 7 ms 9836 KB Output is correct
14 Correct 8 ms 9836 KB Output is correct
15 Correct 8 ms 9964 KB Output is correct
16 Correct 8 ms 9964 KB Output is correct
17 Correct 8 ms 9836 KB Output is correct
18 Correct 8 ms 9964 KB Output is correct
19 Correct 9 ms 9964 KB Output is correct
20 Correct 8 ms 9964 KB Output is correct
21 Correct 8 ms 9964 KB Output is correct
22 Correct 8 ms 9836 KB Output is correct
23 Correct 7 ms 9836 KB Output is correct
24 Correct 8 ms 9964 KB Output is correct
25 Correct 8 ms 9964 KB Output is correct
26 Correct 8 ms 9964 KB Output is correct
27 Correct 8 ms 9964 KB Output is correct
28 Correct 8 ms 9964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 7 ms 9836 KB Output is correct
4 Correct 7 ms 9708 KB Output is correct
5 Correct 8 ms 9836 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 8 ms 9964 KB Output is correct
8 Correct 8 ms 9964 KB Output is correct
9 Correct 7 ms 9836 KB Output is correct
10 Correct 165 ms 27104 KB Output is correct
11 Correct 208 ms 30688 KB Output is correct
12 Correct 202 ms 30304 KB Output is correct
13 Correct 214 ms 31456 KB Output is correct
14 Correct 135 ms 23648 KB Output is correct
15 Correct 8 ms 9964 KB Output is correct
16 Correct 8 ms 9964 KB Output is correct
17 Correct 8 ms 9964 KB Output is correct
18 Correct 7 ms 9836 KB Output is correct
19 Correct 8 ms 9836 KB Output is correct
20 Correct 8 ms 9964 KB Output is correct
21 Correct 8 ms 9964 KB Output is correct
22 Correct 8 ms 9836 KB Output is correct
23 Correct 8 ms 9964 KB Output is correct
24 Correct 21 ms 12332 KB Output is correct
25 Correct 212 ms 31804 KB Output is correct
26 Correct 216 ms 31712 KB Output is correct
27 Correct 230 ms 31456 KB Output is correct
28 Correct 202 ms 30560 KB Output is correct
29 Correct 193 ms 30304 KB Output is correct
30 Correct 176 ms 28256 KB Output is correct
31 Correct 218 ms 32352 KB Output is correct
32 Correct 222 ms 32352 KB Output is correct
33 Correct 122 ms 23648 KB Output is correct
34 Correct 192 ms 30048 KB Output is correct
35 Correct 9 ms 9964 KB Output is correct
36 Correct 8 ms 9964 KB Output is correct
37 Correct 8 ms 9964 KB Output is correct
38 Correct 8 ms 9836 KB Output is correct
39 Correct 7 ms 9836 KB Output is correct
40 Correct 8 ms 9964 KB Output is correct
41 Correct 8 ms 9964 KB Output is correct
42 Correct 8 ms 9964 KB Output is correct
43 Correct 8 ms 9964 KB Output is correct
44 Correct 8 ms 9964 KB Output is correct
45 Correct 148 ms 27868 KB Output is correct
46 Correct 226 ms 33504 KB Output is correct
47 Correct 184 ms 30048 KB Output is correct
48 Correct 150 ms 27616 KB Output is correct
49 Correct 84 ms 19424 KB Output is correct
50 Correct 68 ms 17248 KB Output is correct
51 Correct 123 ms 24848 KB Output is correct
52 Correct 241 ms 36700 KB Output is correct
53 Correct 221 ms 33372 KB Output is correct
54 Correct 287 ms 39840 KB Output is correct
55 Correct 124 ms 25696 KB Output is correct
56 Correct 188 ms 31836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 7 ms 9708 KB Output is correct
4 Correct 8 ms 9836 KB Output is correct
5 Correct 7 ms 9964 KB Output is correct
6 Correct 8 ms 9964 KB Output is correct
7 Correct 8 ms 9964 KB Output is correct
8 Correct 7 ms 9836 KB Output is correct
9 Correct 165 ms 27104 KB Output is correct
10 Correct 208 ms 30688 KB Output is correct
11 Correct 202 ms 30304 KB Output is correct
12 Correct 214 ms 31456 KB Output is correct
13 Correct 135 ms 23648 KB Output is correct
14 Correct 168 ms 27104 KB Output is correct
15 Correct 271 ms 32876 KB Output is correct
16 Correct 262 ms 32272 KB Output is correct
17 Correct 304 ms 33608 KB Output is correct
18 Correct 188 ms 25544 KB Output is correct
19 Correct 183 ms 24452 KB Output is correct
20 Correct 192 ms 24776 KB Output is correct
21 Correct 194 ms 24824 KB Output is correct
22 Correct 186 ms 24776 KB Output is correct
23 Correct 190 ms 24928 KB Output is correct
24 Correct 187 ms 24464 KB Output is correct
25 Correct 187 ms 24672 KB Output is correct
26 Correct 192 ms 24348 KB Output is correct
27 Correct 8 ms 9964 KB Output is correct
28 Correct 8 ms 9964 KB Output is correct
29 Correct 8 ms 9964 KB Output is correct
30 Correct 7 ms 9836 KB Output is correct
31 Correct 8 ms 9836 KB Output is correct
32 Correct 8 ms 9964 KB Output is correct
33 Correct 8 ms 9964 KB Output is correct
34 Correct 8 ms 9836 KB Output is correct
35 Correct 8 ms 9964 KB Output is correct
36 Correct 21 ms 12332 KB Output is correct
37 Correct 212 ms 31804 KB Output is correct
38 Correct 216 ms 31712 KB Output is correct
39 Correct 230 ms 31456 KB Output is correct
40 Correct 202 ms 30560 KB Output is correct
41 Correct 193 ms 30304 KB Output is correct
42 Correct 176 ms 28256 KB Output is correct
43 Correct 218 ms 32352 KB Output is correct
44 Correct 222 ms 32352 KB Output is correct
45 Correct 122 ms 23648 KB Output is correct
46 Correct 192 ms 30048 KB Output is correct
47 Correct 28 ms 12588 KB Output is correct
48 Correct 335 ms 34632 KB Output is correct
49 Correct 327 ms 34124 KB Output is correct
50 Correct 326 ms 38216 KB Output is correct
51 Correct 358 ms 37844 KB Output is correct
52 Correct 295 ms 36112 KB Output is correct
53 Correct 232 ms 30504 KB Output is correct
54 Correct 330 ms 39436 KB Output is correct
55 Correct 339 ms 39496 KB Output is correct
56 Correct 222 ms 31048 KB Output is correct
57 Correct 304 ms 37448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 7 ms 9836 KB Output is correct
4 Correct 7 ms 9708 KB Output is correct
5 Correct 8 ms 9836 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 8 ms 9964 KB Output is correct
8 Correct 8 ms 9964 KB Output is correct
9 Correct 7 ms 9836 KB Output is correct
10 Correct 165 ms 27104 KB Output is correct
11 Correct 208 ms 30688 KB Output is correct
12 Correct 202 ms 30304 KB Output is correct
13 Correct 214 ms 31456 KB Output is correct
14 Correct 135 ms 23648 KB Output is correct
15 Correct 168 ms 27104 KB Output is correct
16 Correct 271 ms 32876 KB Output is correct
17 Correct 262 ms 32272 KB Output is correct
18 Correct 304 ms 33608 KB Output is correct
19 Correct 188 ms 25544 KB Output is correct
20 Correct 183 ms 24452 KB Output is correct
21 Correct 192 ms 24776 KB Output is correct
22 Correct 194 ms 24824 KB Output is correct
23 Correct 186 ms 24776 KB Output is correct
24 Correct 190 ms 24928 KB Output is correct
25 Correct 187 ms 24464 KB Output is correct
26 Correct 187 ms 24672 KB Output is correct
27 Correct 192 ms 24348 KB Output is correct
28 Correct 8 ms 9964 KB Output is correct
29 Correct 8 ms 9964 KB Output is correct
30 Correct 8 ms 9964 KB Output is correct
31 Correct 7 ms 9836 KB Output is correct
32 Correct 8 ms 9836 KB Output is correct
33 Correct 8 ms 9964 KB Output is correct
34 Correct 8 ms 9964 KB Output is correct
35 Correct 8 ms 9836 KB Output is correct
36 Correct 8 ms 9964 KB Output is correct
37 Correct 21 ms 12332 KB Output is correct
38 Correct 212 ms 31804 KB Output is correct
39 Correct 216 ms 31712 KB Output is correct
40 Correct 230 ms 31456 KB Output is correct
41 Correct 202 ms 30560 KB Output is correct
42 Correct 193 ms 30304 KB Output is correct
43 Correct 176 ms 28256 KB Output is correct
44 Correct 218 ms 32352 KB Output is correct
45 Correct 222 ms 32352 KB Output is correct
46 Correct 122 ms 23648 KB Output is correct
47 Correct 192 ms 30048 KB Output is correct
48 Correct 28 ms 12588 KB Output is correct
49 Correct 335 ms 34632 KB Output is correct
50 Correct 327 ms 34124 KB Output is correct
51 Correct 326 ms 38216 KB Output is correct
52 Correct 358 ms 37844 KB Output is correct
53 Correct 295 ms 36112 KB Output is correct
54 Correct 232 ms 30504 KB Output is correct
55 Correct 330 ms 39436 KB Output is correct
56 Correct 339 ms 39496 KB Output is correct
57 Correct 222 ms 31048 KB Output is correct
58 Correct 304 ms 37448 KB Output is correct
59 Correct 96 ms 16556 KB Output is correct
60 Correct 331 ms 34528 KB Output is correct
61 Correct 316 ms 33820 KB Output is correct
62 Correct 361 ms 35528 KB Output is correct
63 Correct 232 ms 27464 KB Output is correct
64 Correct 9 ms 9964 KB Output is correct
65 Correct 8 ms 9964 KB Output is correct
66 Correct 8 ms 9964 KB Output is correct
67 Correct 8 ms 9836 KB Output is correct
68 Correct 7 ms 9836 KB Output is correct
69 Correct 8 ms 9964 KB Output is correct
70 Correct 8 ms 9964 KB Output is correct
71 Correct 8 ms 9964 KB Output is correct
72 Correct 8 ms 9964 KB Output is correct
73 Correct 8 ms 9964 KB Output is correct
74 Correct 148 ms 27868 KB Output is correct
75 Correct 226 ms 33504 KB Output is correct
76 Correct 184 ms 30048 KB Output is correct
77 Correct 150 ms 27616 KB Output is correct
78 Correct 84 ms 19424 KB Output is correct
79 Correct 68 ms 17248 KB Output is correct
80 Correct 123 ms 24848 KB Output is correct
81 Correct 241 ms 36700 KB Output is correct
82 Correct 221 ms 33372 KB Output is correct
83 Correct 287 ms 39840 KB Output is correct
84 Correct 124 ms 25696 KB Output is correct
85 Correct 188 ms 31836 KB Output is correct
86 Correct 73 ms 17432 KB Output is correct
87 Correct 326 ms 37740 KB Output is correct
88 Correct 337 ms 37960 KB Output is correct
89 Correct 238 ms 31616 KB Output is correct
90 Correct 161 ms 23176 KB Output is correct
91 Correct 163 ms 23676 KB Output is correct
92 Correct 227 ms 30012 KB Output is correct
93 Correct 352 ms 40644 KB Output is correct
94 Correct 319 ms 38232 KB Output is correct
95 Correct 393 ms 44200 KB Output is correct
96 Correct 221 ms 30920 KB Output is correct
97 Correct 280 ms 35224 KB Output is correct