Submission #347940

# Submission time Handle Problem Language Result Execution time Memory
347940 2021-01-13T21:18:39 Z MvC Swapping Cities (APIO20_swap) C++14
13 / 100
349 ms 40008 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])
    {
        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 6 ms 9728 KB Output is correct
2 Correct 6 ms 9708 KB Output is correct
3 Correct 6 ms 9728 KB Output is correct
4 Correct 6 ms 9836 KB Output is correct
5 Correct 7 ms 9964 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 7 ms 9964 KB Output is correct
8 Correct 7 ms 9964 KB Output is correct
9 Correct 157 ms 28896 KB Output is correct
10 Correct 200 ms 32736 KB Output is correct
11 Correct 198 ms 32420 KB Output is correct
12 Correct 207 ms 33636 KB Output is correct
13 Correct 118 ms 25824 KB Output is correct
14 Correct 161 ms 29024 KB Output is correct
15 Correct 271 ms 37356 KB Output is correct
16 Correct 263 ms 36644 KB Output is correct
17 Correct 280 ms 38088 KB Output is correct
18 Correct 186 ms 30024 KB Output is correct
19 Correct 89 ms 18604 KB Output is correct
20 Correct 316 ms 38752 KB Output is correct
21 Correct 319 ms 38172 KB Output is correct
22 Correct 338 ms 40008 KB Output is correct
23 Correct 219 ms 31816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9708 KB Output is correct
3 Correct 188 ms 28292 KB Output is correct
4 Correct 193 ms 28872 KB Output is correct
5 Correct 189 ms 28880 KB Output is correct
6 Correct 186 ms 28616 KB Output is correct
7 Correct 196 ms 28768 KB Output is correct
8 Correct 186 ms 28280 KB Output is correct
9 Correct 189 ms 28512 KB Output is correct
10 Correct 186 ms 28188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 6 ms 9728 KB Output is correct
3 Correct 6 ms 9708 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9836 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 7 ms 9964 KB Output is correct
8 Correct 7 ms 9964 KB Output is correct
9 Correct 7 ms 9964 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 9 ms 9964 KB Output is correct
14 Correct 7 ms 9964 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 8 ms 9964 KB Output is correct
19 Correct 7 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 9836 KB Output is correct
24 Incorrect 8 ms 9984 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 6 ms 9728 KB Output is correct
3 Correct 6 ms 9708 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9836 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 7 ms 9964 KB Output is correct
8 Correct 7 ms 9964 KB Output is correct
9 Correct 7 ms 9964 KB Output is correct
10 Correct 157 ms 28896 KB Output is correct
11 Correct 200 ms 32736 KB Output is correct
12 Correct 198 ms 32420 KB Output is correct
13 Correct 207 ms 33636 KB Output is correct
14 Correct 118 ms 25824 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 9 ms 9964 KB Output is correct
19 Correct 7 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 9964 KB Output is correct
23 Correct 8 ms 9964 KB Output is correct
24 Correct 21 ms 12716 KB Output is correct
25 Correct 216 ms 33692 KB Output is correct
26 Correct 211 ms 33504 KB Output is correct
27 Correct 206 ms 33248 KB Output is correct
28 Correct 203 ms 32352 KB Output is correct
29 Correct 194 ms 32096 KB Output is correct
30 Correct 174 ms 29920 KB Output is correct
31 Correct 216 ms 34496 KB Output is correct
32 Correct 217 ms 34144 KB Output is correct
33 Correct 117 ms 25568 KB Output is correct
34 Correct 191 ms 32096 KB Output is correct
35 Correct 7 ms 9836 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 8 ms 9836 KB Output is correct
40 Incorrect 8 ms 9984 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9708 KB Output is correct
3 Correct 6 ms 9728 KB Output is correct
4 Correct 6 ms 9836 KB Output is correct
5 Correct 7 ms 9964 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 7 ms 9964 KB Output is correct
8 Correct 7 ms 9964 KB Output is correct
9 Correct 157 ms 28896 KB Output is correct
10 Correct 200 ms 32736 KB Output is correct
11 Correct 198 ms 32420 KB Output is correct
12 Correct 207 ms 33636 KB Output is correct
13 Correct 118 ms 25824 KB Output is correct
14 Correct 161 ms 29024 KB Output is correct
15 Correct 271 ms 37356 KB Output is correct
16 Correct 263 ms 36644 KB Output is correct
17 Correct 280 ms 38088 KB Output is correct
18 Correct 186 ms 30024 KB Output is correct
19 Correct 188 ms 28292 KB Output is correct
20 Correct 193 ms 28872 KB Output is correct
21 Correct 189 ms 28880 KB Output is correct
22 Correct 186 ms 28616 KB Output is correct
23 Correct 196 ms 28768 KB Output is correct
24 Correct 186 ms 28280 KB Output is correct
25 Correct 189 ms 28512 KB Output is correct
26 Correct 186 ms 28188 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 9 ms 9964 KB Output is correct
31 Correct 7 ms 9964 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 9964 KB Output is correct
35 Correct 8 ms 9964 KB Output is correct
36 Correct 21 ms 12716 KB Output is correct
37 Correct 216 ms 33692 KB Output is correct
38 Correct 211 ms 33504 KB Output is correct
39 Correct 206 ms 33248 KB Output is correct
40 Correct 203 ms 32352 KB Output is correct
41 Correct 194 ms 32096 KB Output is correct
42 Correct 174 ms 29920 KB Output is correct
43 Correct 216 ms 34496 KB Output is correct
44 Correct 217 ms 34144 KB Output is correct
45 Correct 117 ms 25568 KB Output is correct
46 Correct 191 ms 32096 KB Output is correct
47 Correct 28 ms 13100 KB Output is correct
48 Correct 349 ms 38728 KB Output is correct
49 Incorrect 329 ms 38216 KB Output isn't correct
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 6 ms 9728 KB Output is correct
3 Correct 6 ms 9708 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9836 KB Output is correct
6 Correct 7 ms 9964 KB Output is correct
7 Correct 7 ms 9964 KB Output is correct
8 Correct 7 ms 9964 KB Output is correct
9 Correct 7 ms 9964 KB Output is correct
10 Correct 157 ms 28896 KB Output is correct
11 Correct 200 ms 32736 KB Output is correct
12 Correct 198 ms 32420 KB Output is correct
13 Correct 207 ms 33636 KB Output is correct
14 Correct 118 ms 25824 KB Output is correct
15 Correct 161 ms 29024 KB Output is correct
16 Correct 271 ms 37356 KB Output is correct
17 Correct 263 ms 36644 KB Output is correct
18 Correct 280 ms 38088 KB Output is correct
19 Correct 186 ms 30024 KB Output is correct
20 Correct 188 ms 28292 KB Output is correct
21 Correct 193 ms 28872 KB Output is correct
22 Correct 189 ms 28880 KB Output is correct
23 Correct 186 ms 28616 KB Output is correct
24 Correct 196 ms 28768 KB Output is correct
25 Correct 186 ms 28280 KB Output is correct
26 Correct 189 ms 28512 KB Output is correct
27 Correct 186 ms 28188 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 9 ms 9964 KB Output is correct
32 Correct 7 ms 9964 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 9964 KB Output is correct
36 Correct 8 ms 9964 KB Output is correct
37 Correct 21 ms 12716 KB Output is correct
38 Correct 216 ms 33692 KB Output is correct
39 Correct 211 ms 33504 KB Output is correct
40 Correct 206 ms 33248 KB Output is correct
41 Correct 203 ms 32352 KB Output is correct
42 Correct 194 ms 32096 KB Output is correct
43 Correct 174 ms 29920 KB Output is correct
44 Correct 216 ms 34496 KB Output is correct
45 Correct 217 ms 34144 KB Output is correct
46 Correct 117 ms 25568 KB Output is correct
47 Correct 191 ms 32096 KB Output is correct
48 Correct 28 ms 13100 KB Output is correct
49 Correct 349 ms 38728 KB Output is correct
50 Incorrect 329 ms 38216 KB Output isn't correct
51 Halted 0 ms 0 KB -