Submission #58209585
Source Code Expand
//yukicoder@cpp17
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <random>
#include <bitset>
#include <complex>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
*/
int main(){
int n,m;cin>>n>>m;
vector<pair<int,long long>> A[n];
for(int i = 0; m > i; i++){
long long u,v,w;cin>>u>>v>>w;
u--;v--;
A[u].push_back({v, w});
A[v].push_back({u, -w});
}
vector<bool> ansed(n, false);
vector<long long> ans(n, 0);
ansed[0] = true;
stack<int> nxt;
for(int i = n-1; 0 <= i; i--)nxt.push(i);
while(nxt.size()){
int i = nxt.top();nxt.pop();
ansed[i] = true;
for(int j = 0; A[i].size() > j; j++){
if(ansed[i] && ansed[A[i][j].first]){
assert(ans[A[i][j].first]-ans[i] == A[i][j].second);
continue;
}
if(ansed[i]){
ansed[A[i][j].first] = true;
ans[A[i][j].first] = A[i][j].second + ans[i];
nxt.push(A[i][j].first);
}
}
}
for(int i = 0; n > i; i++){
cout << ans[i] << " \n"[i+1 == n];
}
return 0;
}
Submission Info
Submission Time
2024-09-28 21:27:50+0900
Task
D - Hidden Weights
User
CleyL
Language
C++ 20 (gcc 12.2)
Score
400
Code Size
2363 Byte
Status
AC
Exec Time
214 ms
Memory
20856 KiB
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:86:32: warning: comparison of integer expressions of different signedness: ‘std::vector<std::pair<int, long long int> >::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
86 | for(int j = 0; A[i].size() > j; j++){
| ~~~~~~~~~~~~^~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
400 / 400
Status
Set Name
Test Cases
Sample
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name
Status
Exec Time
Memory
00_sample_01.txt
AC
1 ms
3468 KiB
00_sample_02.txt
AC
1 ms
3380 KiB
00_sample_03.txt
AC
1 ms
3508 KiB
01_random_01.txt
AC
70 ms
11184 KiB
01_random_02.txt
AC
168 ms
19420 KiB
01_random_03.txt
AC
185 ms
18604 KiB
01_random_04.txt
AC
184 ms
20720 KiB
01_random_05.txt
AC
15 ms
7824 KiB
01_random_06.txt
AC
97 ms
15576 KiB
01_random_07.txt
AC
191 ms
20012 KiB
01_random_08.txt
AC
213 ms
20856 KiB
01_random_09.txt
AC
20 ms
8840 KiB
01_random_10.txt
AC
177 ms
18908 KiB
01_random_11.txt
AC
186 ms
18172 KiB
01_random_12.txt
AC
214 ms
20816 KiB
01_random_13.txt
AC
39 ms
8872 KiB
01_random_14.txt
AC
191 ms
20456 KiB
01_random_15.txt
AC
184 ms
17956 KiB
01_random_16.txt
AC
208 ms
20808 KiB
01_random_17.txt
AC
98 ms
10952 KiB
01_random_18.txt
AC
112 ms
15996 KiB
01_random_19.txt
AC
157 ms
15476 KiB
01_random_20.txt
AC
187 ms
20740 KiB
02_handmade_01.txt
AC
198 ms
20568 KiB
02_handmade_02.txt
AC
203 ms
20548 KiB
02_handmade_03.txt
AC
207 ms
20564 KiB
02_handmade_04.txt
AC
143 ms
20428 KiB
02_handmade_05.txt
AC
54 ms
7184 KiB
02_handmade_06.txt
AC
155 ms
19956 KiB