結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー |
|
提出日時 | 2021-01-16 13:23:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,536 bytes |
コンパイル時間 | 2,764 ms |
コンパイル使用メモリ | 197,832 KB |
最終ジャッジ日時 | 2025-01-17 21:55:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 49 |
ソースコード
#include<bits/stdc++.h> using namespace std; #pragma region atcoder //#include <atcoder/modint> //using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007; #pragma endregion #pragma region debug for var, v, vv #define debug(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;} #pragma endregion using ll = long long; const ll mod = 1000000007; const int inf = 1001001001; const ll INF = 1001001001001001001ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; } ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // 20 / 3 == 7 ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7 ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p, ll m){ll ret = 1; while(p){if(p & 1){ret = ret * a % m;} a = a * a % m; p >>= 1;} return ret;} /*---------------------------------------------------------------------------------------------------------------------------------*/ int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); int n, m; cin >> n >> m; vector<vector<ll>> g(n, vector<ll>(n)); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ g[i][j] = INF; } g[i][i] = 0; } for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--,b--; ll d; cin >> d; chmin(g[a][b], d); } for(int k = 0; k < n; k++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ chmin(g[i][j], g[i][k] + g[k][j]); } } } for(int i = 0; i < n; i++) g[i][i] = 0; for(int i = 0; i < n; i++){ ll ans = 0; for(int j = 0; j < n; j++){ ans += (g[i][j] == INF ? 0 : g[i][j]); } cout << ans << endl; } } /* * review you code when you get WA (typo? index?) * int overflow, array bounds * special cases (n=1?) */