답안 #106839

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106839 2019-04-20T17:04:50 Z ami Ceste (COCI17_ceste) C++14
160 / 160
2498 ms 760 KB
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

struct edge_t {
	int to,t,c;
	ll w;
};

ll const INFLL=ll(1e18);
int const INF=int(1e9);
int const MAXN=2200;

int N,M;
vector<edge_t> adj[MAXN];
ll res[MAXN];
ll d[MAXN];
tuple<int,int,int> pr[MAXN];

void test(ll x, ll y) {
	rep(i,0,N) {
		for (auto &e:adj[i]) e.w=e.t*x + e.c*y;
	}
	
	rep(i,0,N) {
		d[i]=INFLL;
		pr[i]={-1,-1,-1};
	}
	d[0]=0;
	
	priority_queue<pair<ll,int>> q;
	q.emplace(0,0);
	while (!q.empty()) {
		ll w;
		int v;
		tie(w,v)=q.top();
		w=-w;
		q.pop();
		
		if (w!=d[v]) continue;
		
		for (auto e:adj[v]) {
			int u=e.to;
			if (d[u]>w+e.w) {
				d[u]=w+e.w;
				pr[u]={v,e.t,e.c};
				q.emplace(-d[u],u);
			}
		}
	}
	
	rep(i,1,N) {
		int v=i;
		ll st=0,sc=0;
		while (v!=-1) {
			int t,c;
			tie(v,t,c)=pr[v];
			if (v!=-1) {
				st+=t;
				sc+=c;
			}
		}
		if (st*sc!=0) {
			res[i]=min(res[i],st*sc);
		}
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);
	
	cin>>N>>M;
	rep(i,0,M) {
		int u,v,t,c;
		cin>>u>>v>>t>>c;
		u--, v--;
		adj[u].push_back({v,t,c,0});
		adj[v].push_back({u,t,c,0});
	}

	rep(i,1,N) res[i]=INFLL;
	
	int const MAXX=6500;
	rep(x,0,MAXX+1) test(x,MAXX-x);

	rep(i,1,N) if (res[i]==INFLL) cout<<"-1\n"; else cout<<res[i]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1136 ms 576 KB Output is correct
2 Correct 584 ms 580 KB Output is correct
3 Correct 198 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 500 KB Output is correct
2 Correct 105 ms 500 KB Output is correct
3 Correct 238 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2196 ms 672 KB Output is correct
2 Correct 477 ms 760 KB Output is correct
3 Correct 737 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1866 ms 628 KB Output is correct
2 Correct 1233 ms 760 KB Output is correct
3 Correct 473 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2498 ms 636 KB Output is correct
2 Correct 1716 ms 640 KB Output is correct
3 Correct 1691 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1953 ms 732 KB Output is correct
2 Correct 1708 ms 760 KB Output is correct
3 Correct 1669 ms 672 KB Output is correct