QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#879803#5458. Shortest Path QueryfryanWA 39ms11136kbC++201.5kb2025-02-02 14:47:392025-02-02 14:47:44

Judging History

This is the latest submission verdict.

  • [2025-02-02 14:47:44]
  • Judged
  • Verdict: WA
  • Time: 39ms
  • Memory: 11136kb
  • [2025-02-02 14:47:39]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define int long long

const int inf = 1e9;
const int mxn = 5e4+5;

int n,m,q;
vector<array<int,2>> adj[mxn];
vector<array<int,2>> hull[mxn];

void make_hull(vector<array<int,2>> &a) {
	sort(all(a));
	vector<array<int,2>> hull;
	for (auto pt : a) {		
		if (sz(hull) && hull.back()[0] == pt[0]) continue;

		if (sz(hull) < 2) {
			hull.push_back(pt);
			continue;
		}
		int yy = hull.back()[1];
		if (pt[1] >= yy) continue;
		
		while (sz(hull) >= 2) {
			auto [x1,y1] = hull[sz(hull)-2];
			auto [x2,y2] = hull[sz(hull)-1];
			auto [x3,y3] = pt;
			if (x2*(y3-y1) <= (y2-y1)*(x3-x1)) {
				hull.pop_back();
			} else {
				break;
			}
		}
		hull.push_back(pt);
	}
	swap(a,hull);
	hull.clear();
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	cin>>n>>m;
	for (int i=0; i<m; i++) {
		int u,v,c; cin>>u>>v>>c;
		adj[u-1].push_back({v-1,c});
	}
	hull[0].push_back({0,0});
	for (int i=0; i<n; i++) {
		for (auto [v,t] : adj[i]) {
			if (t) {
				for (auto [x,y] : hull[i]) {
					hull[v].push_back({x,y+1});
				}
			} else {
				for (auto [x,y] : hull[i]) {
					hull[v].push_back({x+1,y});
				}
			}
			make_hull(hull[v]);
		}
	}
	cin>>q;
	while (q--) {
		int a,b,v; cin>>a>>b>>v; --v;
		int mv = inf;
		for (auto [x,y] : hull[v]) {
			mv = min(mv,x*a+y*b);
		}
		cout<<mv<<"\n";
	}
	
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

input:

4 4
1 2 0
1 3 1
2 4 0
3 4 1
3
3 5 2
3 2 4
2 3 4

output:

3
4
4

result:

ok 3 number(s): "3 4 4"

Test #2:

score: -100
Wrong Answer
time: 39ms
memory: 11136kb

input:

50000 100000
1 2 1
2 3 0
3 4 1
4 5 0
5 6 1
6 7 0
7 8 1
8 9 1
9 10 0
10 11 1
11 12 1
12 13 1
13 14 0
14 15 0
15 16 0
16 17 0
17 18 1
18 19 1
19 20 0
20 21 1
21 22 0
22 23 0
23 24 1
24 25 1
25 26 0
26 27 1
27 28 0
28 29 0
29 30 0
30 31 0
31 32 1
32 33 0
33 34 1
34 35 1
35 36 1
36 37 1
37 38 0
38 39 0
...

output:

171090050
213493702
236693474
259699419
89732820
16685198
47102088
64713954
46949896
245672377
94777502
84753103
267419449
173654876
216482422
147454419
111021650
80187604
184782450
78138570
86528820
207116030
191332392
202049239
297586630
173714177
174899498
97998224
96431009
280559577
164349486
27...

result:

wrong answer 1st numbers differ - expected: '164602050', found: '171090050'