Submission #59020980


Source Code Expand

#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef modint1000000007 mi;
constexpr ll mod=1000000007;

struct edge{
	ll to,cost;
};

vector<edge>G[100005];

vector<ll> dijkstra(int s,int N){
	vector<ll>d(N,1e18);
	d[s]=0;
	priority_queue<P,vector<P>,greater<P>>Q;
	Q.push({0,s});

	while(Q.size()){
		P p=Q.top();
		Q.pop();
		int v=p.second;
		if(d[v]<p.first)continue;

		for(auto e:G[v]){
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				Q.push({d[e.to],e.to});
			}
		}
	}
	return d;
}

int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		ll a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		G[a].push_back({b,c});
		G[b].push_back({a,c});
	}
	vector<ll>d0=dijkstra(0,n),dn=dijkstra(n-1,n);

	rep(i,n){
		cout<<d0[i]+dn[i]<<endl;
	}

}

Submission Info

Submission Time
Task 013 - Passing(★5)
User Rho17
Language C++ 20 (gcc 12.2)
Score 5
Code Size 945 Byte
Status AC
Exec Time 222 ms
Memory 15532 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 5 / 5
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_1.txt, sample_2.txt, sample_3.txt
All killer_1.txt, killer_2.txt, killer_3.txt, line_1.txt, line_2.txt, line_3.txt, rand_1.txt, rand_2.txt, rand_3.txt, rand_4.txt, rand_5.txt, rand_6.txt, rand_7.txt, sample_1.txt, sample_2.txt, sample_3.txt, star_1.txt, star_2.txt, star_3.txt
Case Name Status Exec Time Memory
killer_1.txt AC 10 ms 4104 KiB
killer_2.txt AC 133 ms 10740 KiB
killer_3.txt AC 2 ms 3544 KiB
line_1.txt AC 195 ms 12208 KiB
line_2.txt AC 222 ms 12124 KiB
line_3.txt AC 216 ms 12212 KiB
rand_1.txt AC 162 ms 11264 KiB
rand_2.txt AC 98 ms 10184 KiB
rand_3.txt AC 153 ms 11180 KiB
rand_4.txt AC 136 ms 10436 KiB
rand_5.txt AC 111 ms 10212 KiB
rand_6.txt AC 119 ms 10200 KiB
rand_7.txt AC 138 ms 10808 KiB
sample_1.txt AC 2 ms 3544 KiB
sample_2.txt AC 2 ms 3568 KiB
sample_3.txt AC 2 ms 3508 KiB
star_1.txt AC 206 ms 15532 KiB
star_2.txt AC 216 ms 15432 KiB
star_3.txt AC 212 ms 15424 KiB