結果

問題 No.1344 Typical Shortest Path Sum
コンテスト
ユーザー PCTprobability
提出日時 2021-01-13 20:57:03
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,515 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,673 ms
コンパイル使用メモリ 175,724 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-20 23:04:59
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 77
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:25:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   ll dp[n][n];
      |            ^
main.cpp:25:12: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:23:6: note: declared here
   23 |   ll n,m;
      |      ^
main.cpp:25:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   ll dp[n][n];
      |         ^
main.cpp:25:9: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:23:6: note: declared here
   23 |   ll n,m;
      |      ^
2 warnings generated.

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ll n,m;
  cin>>n>>m;
  ll dp[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
        dp[i][j]=0;
      }
      else{
        dp[i][j]=inf;
      }
    }
  }
  for(int i=0;i<m;i++){
    ll x,y,d;
    cin>>x>>y>>d;
    x--;
    y--;
    chmin(dp[x][y],d);
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
          if(dp[j][i]<=inf/2&&dp[i][k]<=inf/2){
              chmin(dp[j][k],dp[j][i]+dp[i][k]);
          }
      }
    }
  }
  for(int i=0;i<n;i++){
    ll tmp=0;
    for(int j=0;j<n;j++){
      if(dp[i][j]<=inf/2){
        tmp+=dp[i][j];
      }
    }
    cout<<tmp<<endl;
  }
}
0