Submission #1103162

# Submission time Handle Problem Language Result Execution time Memory
1103162 2024-10-20T12:14:25 Z duyhoanho Cities (BOI16_cities) C++14
0 / 100
187 ms 144060 KB
#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N = 1e5+10, oo = 1e16;
int n,f[N][70],k,m;
int b[N];
vector<pii> ad[N];
struct node
{
    int u,w,mask;
};
struct cmp
{
    bool operator() (node a,node b)
    {
        a.w > b.w;
    }
};
void dij(int mask)
{
    priority_queue<node,vector<node>,cmp> q;
    forinc(i,1,n) q.push({i,f[i][mask],mask});
    while(q.size())
    {
        auto[u,w,mas] = q.top();q.pop();
        if(w > f[u][mas]) continue;
        for(auto v : ad[u])
        {
            int nm = mas | b[v.fi];
            if(f[v.fi][nm] > w + v.se)
            {
                f[v.fi][nm] = w + v.se;
                q.push({v.fi,f[v.fi][nm],nm});
            }
        }
    }
}
int32_t main()
{
    #define task "task"
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>m;
    int it = 0;
    forinc(i,1,k)
    {
        int x;
        cin>>x;
        b[x] = (1<<it);
        it++;
    }
    forinc(i,1,m)
    {
        int u,v,c;
        cin>>u>>v>>c;
        ad[u].pb({v,c});
        ad[v].pb({u,c});
    }
    forinc(i,0,n)
    {
        forinc(j,0,70) f[i][j] = oo;
    }
    forinc(i,1,n)
    {
        f[i][b[i]] = 0;
    }
    for(int mask = 0 ; mask < (1 << k) ; mask ++)
    {
        for(int s1 = 0 ; s1 < (1 << k) ; s1++)
        {
            int s2 = mask ^ s1;
            for(int i = 1 ; i <= n ; i++) f[i][mask] = min(f[i][mask] , f[i][s1] + f[i][s2]);
        }
        dij(mask);
    }
    int ans = oo;

    forinc(i,1,n)
    {
        ans = min(ans , f[i][(1<<k) - 1]);
    }
    cout<<ans;

}

Compilation message

cities.cpp: In member function 'bool cmp::operator()(node, node)':
cities.cpp:22:13: warning: statement has no effect [-Wunused-value]
   22 |         a.w > b.w;
      |         ~~~~^~~~~
cities.cpp:23:5: warning: no return statement in function returning non-void [-Wreturn-type]
   23 |     }
      |     ^
cities.cpp: In function 'void dij(long long int)':
cities.cpp:31:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |         auto[u,w,mas] = q.top();q.pop();
      |             ^
cities.cpp: In function 'int32_t main()':
cities.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cities.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:72:32: warning: iteration 70 invokes undefined behavior [-Waggressive-loop-optimizations]
   72 |         forinc(j,0,70) f[i][j] = oo;
      |                        ~~~~~~~~^~~~
cities.cpp:2:36: note: within this loop
    2 | #define forinc(i,a,b) for(int i=a;i<=b;i++)
......
   72 |         forinc(j,0,70) f[i][j] = oo;
      |                ~~~~~~               
cities.cpp:72:9: note: in expansion of macro 'forinc'
   72 |         forinc(j,0,70) f[i][j] = oo;
      |         ^~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 9296 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 174 ms 143792 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 9552 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 187 ms 144060 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 172 ms 143800 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -