답안 #982363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982363 2024-05-14T07:26:26 Z simona1230 자매 도시 (APIO20_swap) C++17
13 / 100
2000 ms 52284 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

int maxx,minn,maxw;
int n,m,x,y;
vector<int> v[100001],w[100001],num[100001];
pair<int,int> p[100001];
bool sec=1;

struct edge
{
    int x,y,d;
    edge(){}
    edge(int _x,int _y,int _d)
    {
        x=_x;
        y=_y;
        d=_d;
    }

    bool operator<(const edge&e)const
    {
        return e.d<d;
    }
};

void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    minn=N;
    n=N;
    m=M;
    for(int i=0;i<m;i++)
    {
        if(U[i]!=0)sec=0;
        maxw=max(maxw,W[i]);
        v[U[i]].push_back(V[i]);
        v[V[i]].push_back(U[i]);
        w[U[i]].push_back(W[i]);
        w[V[i]].push_back(W[i]);
        num[U[i]].push_back(i);
        num[V[i]].push_back(i);
        maxx=max(maxx,(int)v[U[i]].size());
        maxx=max(maxx,(int)v[V[i]].size());
        p[i]={W[i],V[i]};
    }
    sort(p,p+m);

    for(int i=0;i<n;i++)
    {
        minn=min(minn,(int)v[i].size());
    }
}

int d[1024][1024];
void dijkstra()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            d[i][j]=1e9+1;
        }
    }

    priority_queue<edge> q;

    q.push({x,y,0});
    d[x][y]=0;

    while(q.size())
    {
        edge e=q.top();
        q.pop();
        //cout<<e.x<<" "<<e.y<<" "<<e.d<<endl;

        if(d[e.x][e.y]>=e.d)
        {
            for(int i=0;i<v[e.x].size();i++)
            {
                for(int j=0;j<v[e.y].size();j++)
                {
                    int nb1=v[e.x][i],nb2=v[e.y][j];

                    if(nb2!=e.x)
                    {
                        if(d[e.x][nb2]>max(d[e.x][e.y],w[e.y][j]))
                        {
                            d[e.x][nb2]=max(d[e.x][e.y],w[e.y][j]);
                            q.push({e.x,nb2,d[e.x][nb2]});
                        }
                    }
                    if(nb1!=e.y)
                    {
                        if(d[nb1][e.y]>max(d[nb1][e.y],w[e.x][i]))
                        {
                            d[nb1][e.y]=max(d[nb1][e.y],w[e.x][i]);
                            q.push({nb1,e.y,d[nb1][e.y]});
                        }
                    }

                    if(num[e.x][i]==num[e.y][j]||nb1==nb2)continue;

                    int wg=max(w[e.x][i],w[e.y][j]);
                    if(d[nb1][nb2]>max(d[e.x][e.y],wg))
                    {
                        d[nb1][nb2]=max(d[e.x][e.y],wg);
                        q.push({nb1,nb2,d[nb1][nb2]});
                    }
                }
            }

        }
    }
}

int getMinimumFuelCapacity(int X, int Y)
{
    x=X;
    y=Y;
    if(maxx<=2)
    {
        if(minn==1)return -1;
        return maxw;
    }

    if(sec)
    {
        if(x==0||y==0)
        {
            if(x>y)swap(x,y);
            int i1=0,i2=1;
            if(p[0].second==y)i1=2;
            if(p[1].second==y)i2=2;
            int ans=max(p[i1].first,p[i2].first);
            ans=max(ans,w[y][0]);
            return ans;
        }
        int ans=p[0].first;
        if(p[0].second==x||p[0].second==y)ans=p[1].first;
        if(p[1].second==x||p[1].second==y)ans=p[2].first;
        ans=max(ans,w[x][0]);
        ans=max(ans,w[y][0]);
        return ans;
    }

    dijkstra();
    int ans=d[y][x];
    if(ans==1e9+1)ans=-1;
    return ans;
}
/*
5 4
0 1 1
0 2 2
0 3 3
0 4 4
4
0 1
0 2
0 3
0 4

*/

Compilation message

swap.cpp: In function 'void dijkstra()':
swap.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for(int i=0;i<v[e.x].size();i++)
      |                         ~^~~~~~~~~~~~~~
swap.cpp:81:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                 for(int j=0;j<v[e.y].size();j++)
      |                             ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10076 KB Output is correct
3 Correct 2 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 58 ms 19340 KB Output is correct
10 Correct 76 ms 21332 KB Output is correct
11 Correct 69 ms 21008 KB Output is correct
12 Correct 75 ms 21876 KB Output is correct
13 Correct 76 ms 21840 KB Output is correct
14 Correct 56 ms 19280 KB Output is correct
15 Correct 149 ms 23264 KB Output is correct
16 Correct 106 ms 22788 KB Output is correct
17 Correct 115 ms 23480 KB Output is correct
18 Correct 132 ms 23448 KB Output is correct
19 Correct 53 ms 15696 KB Output is correct
20 Correct 112 ms 24480 KB Output is correct
21 Correct 111 ms 24336 KB Output is correct
22 Correct 120 ms 25020 KB Output is correct
23 Correct 131 ms 25276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10076 KB Output is correct
3 Correct 122 ms 25180 KB Output is correct
4 Correct 102 ms 25636 KB Output is correct
5 Correct 103 ms 25684 KB Output is correct
6 Correct 103 ms 25736 KB Output is correct
7 Correct 105 ms 25660 KB Output is correct
8 Correct 100 ms 25116 KB Output is correct
9 Correct 105 ms 25644 KB Output is correct
10 Correct 97 ms 25204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10076 KB Output is correct
3 Correct 2 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 2 ms 10076 KB Output is correct
10 Correct 463 ms 22408 KB Output is correct
11 Correct 413 ms 15184 KB Output is correct
12 Correct 420 ms 17984 KB Output is correct
13 Correct 324 ms 17804 KB Output is correct
14 Correct 410 ms 17688 KB Output is correct
15 Correct 418 ms 18456 KB Output is correct
16 Correct 388 ms 14972 KB Output is correct
17 Correct 407 ms 17864 KB Output is correct
18 Correct 518 ms 24804 KB Output is correct
19 Correct 458 ms 24252 KB Output is correct
20 Correct 443 ms 17704 KB Output is correct
21 Correct 813 ms 23796 KB Output is correct
22 Correct 594 ms 18152 KB Output is correct
23 Correct 452 ms 17620 KB Output is correct
24 Execution timed out 2016 ms 52284 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Correct 3 ms 10072 KB Output is correct
3 Correct 2 ms 10076 KB Output is correct
4 Correct 2 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 3 ms 10072 KB Output is correct
10 Correct 58 ms 19340 KB Output is correct
11 Correct 76 ms 21332 KB Output is correct
12 Correct 69 ms 21008 KB Output is correct
13 Correct 75 ms 21876 KB Output is correct
14 Correct 76 ms 21840 KB Output is correct
15 Correct 463 ms 22408 KB Output is correct
16 Correct 413 ms 15184 KB Output is correct
17 Correct 420 ms 17984 KB Output is correct
18 Correct 324 ms 17804 KB Output is correct
19 Correct 410 ms 17688 KB Output is correct
20 Correct 418 ms 18456 KB Output is correct
21 Correct 388 ms 14972 KB Output is correct
22 Correct 407 ms 17864 KB Output is correct
23 Correct 518 ms 24804 KB Output is correct
24 Correct 458 ms 24252 KB Output is correct
25 Correct 443 ms 17704 KB Output is correct
26 Correct 813 ms 23796 KB Output is correct
27 Correct 594 ms 18152 KB Output is correct
28 Correct 452 ms 17620 KB Output is correct
29 Execution timed out 2016 ms 52284 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10076 KB Output is correct
3 Correct 2 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 58 ms 19340 KB Output is correct
10 Correct 76 ms 21332 KB Output is correct
11 Correct 69 ms 21008 KB Output is correct
12 Correct 75 ms 21876 KB Output is correct
13 Correct 76 ms 21840 KB Output is correct
14 Correct 56 ms 19280 KB Output is correct
15 Correct 149 ms 23264 KB Output is correct
16 Correct 106 ms 22788 KB Output is correct
17 Correct 115 ms 23480 KB Output is correct
18 Correct 132 ms 23448 KB Output is correct
19 Correct 122 ms 25180 KB Output is correct
20 Correct 102 ms 25636 KB Output is correct
21 Correct 103 ms 25684 KB Output is correct
22 Correct 103 ms 25736 KB Output is correct
23 Correct 105 ms 25660 KB Output is correct
24 Correct 100 ms 25116 KB Output is correct
25 Correct 105 ms 25644 KB Output is correct
26 Correct 97 ms 25204 KB Output is correct
27 Correct 463 ms 22408 KB Output is correct
28 Correct 413 ms 15184 KB Output is correct
29 Correct 420 ms 17984 KB Output is correct
30 Correct 324 ms 17804 KB Output is correct
31 Correct 410 ms 17688 KB Output is correct
32 Correct 418 ms 18456 KB Output is correct
33 Correct 388 ms 14972 KB Output is correct
34 Correct 407 ms 17864 KB Output is correct
35 Correct 518 ms 24804 KB Output is correct
36 Runtime error 46 ms 27788 KB Execution killed with signal 11
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Correct 3 ms 10072 KB Output is correct
3 Correct 2 ms 10076 KB Output is correct
4 Correct 2 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 3 ms 10072 KB Output is correct
10 Correct 58 ms 19340 KB Output is correct
11 Correct 76 ms 21332 KB Output is correct
12 Correct 69 ms 21008 KB Output is correct
13 Correct 75 ms 21876 KB Output is correct
14 Correct 76 ms 21840 KB Output is correct
15 Correct 56 ms 19280 KB Output is correct
16 Correct 149 ms 23264 KB Output is correct
17 Correct 106 ms 22788 KB Output is correct
18 Correct 115 ms 23480 KB Output is correct
19 Correct 132 ms 23448 KB Output is correct
20 Correct 122 ms 25180 KB Output is correct
21 Correct 102 ms 25636 KB Output is correct
22 Correct 103 ms 25684 KB Output is correct
23 Correct 103 ms 25736 KB Output is correct
24 Correct 105 ms 25660 KB Output is correct
25 Correct 100 ms 25116 KB Output is correct
26 Correct 105 ms 25644 KB Output is correct
27 Correct 97 ms 25204 KB Output is correct
28 Correct 463 ms 22408 KB Output is correct
29 Correct 413 ms 15184 KB Output is correct
30 Correct 420 ms 17984 KB Output is correct
31 Correct 324 ms 17804 KB Output is correct
32 Correct 410 ms 17688 KB Output is correct
33 Correct 418 ms 18456 KB Output is correct
34 Correct 388 ms 14972 KB Output is correct
35 Correct 407 ms 17864 KB Output is correct
36 Correct 518 ms 24804 KB Output is correct
37 Runtime error 46 ms 27788 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -