답안 #1083032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083032 2024-09-02T10:20:21 Z User0069 Cities (BOI16_cities) C++17
51 / 100
6000 ms 262144 KB
#include<bits/stdc++.h>
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);
const int maxn=2e5+33;
const int N=1e5;
const int mod=1e9+7;
const int INF=1e18;
int n,k,m,imp[maxn],dp[maxn][32],vis[maxn][32];
vector<int> adj[maxn];
struct edge
{
    int u,v,w;
}e[maxn];
struct ele
{
    int des,mask,dis,cnt;
};
bool operator <(ele a,ele b)
{
    if(a.cnt==b.cnt) return a.dis>b.dis;
    return a.cnt>b.cnt;
}
priority_queue<ele> pq;
void dijkstra()
{
    for(int i=1;i<=n;i++)
    {
        if(imp[i])
        {
            pq.push({i,0,0});
        }
    }
    while(!pq.empty())
    {
        int des=pq.top().des;
        int dis=pq.top().dis;
        int mask=pq.top().mask;
        pq.pop();
        if(imp[des]) mask|=(1<<(imp[des]-1));
        if(vis[des][mask]) continue;
        dp[des][mask]=dis;
        vis[des][mask]=1;
        for(int i:adj[des])
        {
            int des1=e[i].u+e[i].v-des;
            pq.push({des1,mask,dis+e[i].w});
        }
        for(int i=1;i<(1<<k);i++)
        {
            if((i|mask)==mask)
            {
                if(vis[des][i]==0)
                {
                    dp[des][i]=dp[des][mask];
                    vis[des][i]=1;
                }
            }
        }
        for(int i=1;i<(1<<k);i++)
        {
            if((i|mask)==i)
            {
                if(vis[des][mask^i]&&!vis[des][i])
                {
                    pq.push({des,i,dp[des][mask]+dp[des][i^mask]});
                }
            }
        }
    }
}
signed main()
{
    if (fopen(taskname".INP","r"))
    {
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    Faster
    cin>>n>>k>>m;
    for(int i=1;i<=k;i++)
    {
        int x;
        cin>>x;
        imp[x]=i;
    }
    for(int i=1;i<=m;i++)
    {
        cin>>e[i].u>>e[i].v>>e[i].w;
        adj[e[i].u].push_back(i);
        adj[e[i].v].push_back(i);
    }
    dijkstra();
    int ans=INF;
    for(int i=1;i<=n;i++)
    {
        if(vis[i][(1<<k)-1]) ans=min(ans,dp[i][(1<<k)-1]);
    }
    cout<<ans;
}


Compilation message

cities.cpp: In function 'int main()':
cities.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(taskname".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(taskname".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1687 ms 98940 KB Output is correct
2 Correct 1839 ms 98576 KB Output is correct
3 Correct 375 ms 69048 KB Output is correct
4 Correct 1521 ms 146236 KB Output is correct
5 Correct 541 ms 82764 KB Output is correct
6 Correct 515 ms 80468 KB Output is correct
7 Correct 7 ms 6104 KB Output is correct
8 Correct 5 ms 5976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6868 KB Output is correct
2 Correct 16 ms 6868 KB Output is correct
3 Correct 5 ms 5980 KB Output is correct
4 Correct 13 ms 6608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5607 ms 197600 KB Output is correct
2 Execution timed out 6077 ms 197328 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3030 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -