답안 #247683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
247683 2020-07-11T23:22:25 Z kimbj0709 Cities (BOI16_cities) C++14
100 / 100
2201 ms 46572 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100050
#define f first
#define s second
vector<vector<pair<int,int> > > adj(maxn);
#define INT_MAX LLONG_MAX/3
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int no_of_vertex,no_of_special,no_of_edge;
  int input1,input2,input3;
  cin >> no_of_vertex >> no_of_special >> no_of_edge;
  int dist[1<<no_of_special][no_of_vertex+5];
  vector<int> special;
  for(int i=0;i<no_of_special;i++){
    cin >> input1;
    special.push_back(input1);
  }
  for(int i=0;i<no_of_edge;i++){
    cin >> input1 >> input2 >> input3;
    adj[input1].push_back({input2,input3});
    adj[input2].push_back({input1,input3});
  }
  for(int i=0;i<(1<<no_of_special);i++){
    for(int j=0;j<no_of_vertex+5;j++){
      dist[i][j] = INT_MAX;
    }
  }
  for(int i=0;i<no_of_special;i++){
    dist[1<<i][special[i]] = 0;
  }
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >  q1;
  for(int i=1;i<(1<<no_of_special);i++){
    for(int j=0;j<i;j++){
      if((j|i)!=i){
        continue;
      }
      int comp = i^j;
      for(int a=1;a<=no_of_vertex;a++){
        dist[i][a] = min(dist[i][a],dist[j][a]+dist[comp][a]);
      }
    }
    for(int j=1;j<=no_of_vertex;j++){
      if(dist[i][j]!=INT_MAX){
        q1.push({dist[i][j],j});
      }
    }
    while(q1.size()!=0){
      pair<int,int> a = q1.top();
      q1.pop();
      if(dist[i][a.s]!=a.f){
        continue;
      }
      for(auto k:adj[a.s]){
        if(dist[i][k.f]>a.f+k.s){
          dist[i][k.f] = a.f+k.s;
          q1.push({dist[i][k.f],k.f});
        }
      }
    }
  }
  /*for(int i=0;i<(1<<no_of_special);i++){
    for(int j=1;j<=no_of_vertex;j++){
      cout << dist[i][j] << ' ';
    }
    cout << endl;
  }*/
  int mini = INT_MAX;
  for(int i=1;i<=no_of_vertex;i++){
    //cout << dist[(1<<no_of_special)-1][i] << " ";
    mini = min(mini,dist[(1<<no_of_special)-1][i]);
  }
  cout << mini;
}

Compilation message

cities.cpp:8:0: warning: "INT_MAX" redefined
 #define INT_MAX LLONG_MAX/3
 
In file included from /usr/include/c++/7/climits:42:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:39,
                 from cities.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:120:0: note: this is the location of the previous definition
 #define INT_MAX __INT_MAX__
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 567 ms 27904 KB Output is correct
2 Correct 524 ms 26980 KB Output is correct
3 Correct 313 ms 18540 KB Output is correct
4 Correct 79 ms 15096 KB Output is correct
5 Correct 311 ms 24732 KB Output is correct
6 Correct 75 ms 15096 KB Output is correct
7 Correct 9 ms 2944 KB Output is correct
8 Correct 8 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3072 KB Output is correct
2 Correct 11 ms 3072 KB Output is correct
3 Correct 9 ms 2944 KB Output is correct
4 Correct 9 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1087 ms 34216 KB Output is correct
2 Correct 1024 ms 33112 KB Output is correct
3 Correct 664 ms 24812 KB Output is correct
4 Correct 603 ms 25836 KB Output is correct
5 Correct 186 ms 17252 KB Output is correct
6 Correct 88 ms 17528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2136 ms 46568 KB Output is correct
2 Correct 2201 ms 46572 KB Output is correct
3 Correct 2104 ms 45660 KB Output is correct
4 Correct 1590 ms 37356 KB Output is correct
5 Correct 1107 ms 31984 KB Output is correct
6 Correct 278 ms 18652 KB Output is correct
7 Correct 98 ms 17272 KB Output is correct