Submission #940570

# Submission time Handle Problem Language Result Execution time Memory
940570 2024-03-07T10:49:36 Z groshi Wild Boar (JOI18_wild_boar) C++17
0 / 100
2 ms 14940 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int mam[100100];
struct wi{
    vector<int> Q;
    int dp[100100][2][2];///koszt, od kogo
}*w;
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,m,t,l,x,y,z;
    cin>>n>>m>>t>>l;
    w=new wi[n+3];
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y>>z;
        w[x].Q.push_back(y);
        w[x].Q.push_back(z);
        w[y].Q.push_back(x);
        w[y].Q.push_back(z);
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<=l;j++)
            w[i].dp[j][0][0]=1e18,w[i].dp[j][0][1]=1e18;
    for(int i=1;i<=l;i++)
        cin>>mam[i];
    cin>>x>>y;
    mam[x]=y;
    priority_queue<pair<pair<int,int>,pair<int,int> > > kolejka;
    kolejka.push({{0,mam[1]},{0,0}});
    w[mam[1]].dp[1][0][0]=0;
    while(!kolejka.empty())
    {
        auto para=kolejka.top();
        kolejka.pop();
        int x=para.first.second;
        int koszt=-para.first.first;
        int gdzie=para.second.first;
        int skad=para.second.second;
        if(mam[gdzie+1]==x)
            gdzie++;
        if((w[x].dp[gdzie][0][0]!=koszt || w[x].dp[gdzie][1][0]!=skad) && (w[x].dp[gdzie][0][1]!=koszt || w[x].dp[gdzie][1][1]!=skad))
            continue;
        for(int i=0;i<w[x].Q.size();i+=2)
        {
            int pom=w[x].Q[i];
            int ile=w[x].Q[i+1];
            if(pom==skad)
                continue;
            if(mam[gdzie+1]==pom)
                gdzie++;
            if(w[pom].dp[gdzie][0][1]<=koszt+ile)
            {
                if(mam[gdzie]==pom)
                    gdzie--;
                continue;
            }
            if(w[pom].dp[gdzie][0][0]>koszt+ile)
            {
                w[pom].dp[gdzie][0][0]=koszt+ile;
                w[pom].dp[gdzie][1][0]=x;
            }
            else if(w[pom].dp[gdzie][0][1]>koszt+ile)
            {
                if(x==w[pom].dp[gdzie][1][0])
                {
                    if(mam[gdzie]==pom)
                        gdzie--;
                    continue;
                }
                w[pom].dp[gdzie][0][1]=koszt+ile;
                w[pom].dp[gdzie][1][1]=x;
            }
            kolejka.push({{-koszt-ile,pom},{gdzie,x}});
        }
    }
    if(w[mam[l]].dp[l][0][0]==1000000000000000000)
        cout<<"-1";
    else cout<<w[mam[l]].dp[l][0][0];
    return 0;
}

Compilation message

wild_boar.cpp: In function 'int32_t main()':
wild_boar.cpp:47:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=0;i<w[x].Q.size();i+=2)
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -