QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#311570#8136. Rebellious Edgeucup-team1266WA 33ms3576kbC++201.4kb2024-01-22 15:19:042024-01-22 15:19:05

Judging History

你现在查看的是最新测评结果

  • [2024-01-22 15:19:05]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:3576kb
  • [2024-01-22 15:19:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
const int MAX = 4e5 + 10, mod = 998244353;

int n, m;
vector<pii> graph[MAX];
array<int, 3> spc;
bool vis[MAX];
int dp[MAX];
void solve(){
	cin >> n >> m;
	for (int i = 1; i <= n; ++ i) graph[i].clear(), dp[i] = 1e9;
	for (int i = 0; i < m; ++ i){
		int u, v, w;
		cin >> u >> v >> w;
		if (u > v) spc = {u, v, w};
		else graph[v].push_back({w, u});
	}
	for (int i = 1; i <= n; ++ i) sort(graph[i].begin(), graph[i].end());
	int ans1 = 0, ans2 = spc[2];
	for (int i = 2; i <= n; ++ i){
		if (graph[i].size() == 0) ans1 = 1e9;
		else ans1 += graph[i].front().first;
	}
	for (int i = 2; i <= n; ++ i){
		if (i == spc[1]) continue;
		if (graph[i].size() == 0) ans2 = 1e9;
		else ans2 += graph[i].front().first;
	}
	for (int i = spc[1] + 1; i <= spc[0]; ++ i){
		for (auto [w, u]: graph[i]){
			if (u < spc[1]) dp[i] = min(dp[i], w - graph[i].front().first);
			else dp[i] = min(dp[i], w - graph[i].front().first + dp[u]);
		}
	}
	ans2 += dp[spc[0]];
	if (spc[1] == 1) ans2 = 1e9;
	cout << min(ans1, ans2) << endl;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//cout << fixed << setprecision(7);
	int _;cin>>_;while (_ --)
		solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3576kb

input:

3
5 6
1 2 4
1 3 2
2 3 0
3 4 1
4 5 1
5 2 1
4 4
1 2 4
1 3 6
1 4 8
4 2 1000000
3 3
1 2 100
2 1 10
2 3 1000

output:

5
18
1100

result:

ok 3 number(s): "5 18 1100"

Test #2:

score: -100
Wrong Answer
time: 33ms
memory: 3552kb

input:

50000
4 5
2 4 998973548
2 3 501271695
4 1 778395982
1 4 32454891
1 2 757288934
4 5
1 4 720856669
2 3 665098951
3 4 407461517
2 1 866914401
1 2 457859826
4 5
1 2 75288664
1 4 624893594
3 2 458973866
2 4 769074655
2 3 834773751
4 5
2 3 237060634
2 4 297307882
3 4 200383586
1 2 42856502
3 1 16574713
4 ...

output:

1000000000
1000000000
-1376326085
480300722
1000000000
1541095843
-1801117808
858095911
1034153425
793861088
605832428
1000000000
612891589
1000000000
517769091
1000000000
1000000000
93634961
960978736
984886788
1000000000
1002892611
1000000000
1000000000
1000000000
977157479
1000000000
654475526
14...

result:

wrong answer 1st numbers differ - expected: '1291015520', found: '1000000000'