UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213197#2675. Road Reformfddwd101746ms22364kbC++111.4kb2024-11-09 22:55:352024-11-09 23:31:06

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200010
#define pint pair<int,int>
#define fir first
#define sec second
int n,m,k,dfn[MAXN],low[MAXN],js=0,cnt=0,pid[MAXN];
vector<pint>g[MAXN];
vector<int>jev[MAXN];
stack<int>spt;
void tarjan(int id,int fr){
	dfn[id]=low[id]=++js;spt.push(id);
	vector<int>base;
	for(int i=0;i<g[id].size();++i)if(g[id][i].fir!=fr)
		if(!dfn[g[id][i].fir]){
			tarjan(g[id][i].fir,id);
			low[id]=min(low[id],low[g[id][i].fir]);
		}else low[id]=min(low[id],dfn[g[id][i].fir]);
	if(dfn[id]==low[id]){
		int v;++cnt;
		do{v=spt.top(),spt.pop();pid[v]=cnt;}while(v!=id);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1,u,v,w;i<=m;++i)
		cin>>u>>v>>w,g[u].push_back({v,w}),g[v].push_back({u,w});
	for(int i=1;i<=n;++i)if(!dfn[i]){
		tarjan(i,0);
		if(!spt.empty())
			++cnt;while(!spt.empty()) pid[spt.top()]=cnt,spt.pop();
	}vector<int>mik;
	for(int i=1;i<=n;++i)for(int j=0;j<g[i].size();++j)
		if(pid[i]!=pid[g[i][j].fir]) mik.push_back(g[i][j].sec);
		else jev[pid[i]].push_back(g[i][j].sec);
	ll ans=0;
	for(int i=0;i<mik.size();++i) ans+=max(0,mik[i]-k);
	for(int i=1;i<=cnt;++i){
		int val=INT_MAX;
		for(int j=0;j<jev[i].size();++j)
			if(abs(val-k)>abs(jev[i][j]-k)) val=jev[i][j];
		if(val!=INT_MAX) ans+=abs(val-k);
	}cout<<ans<<endl;
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 10660kb

input:

20 80 10
11 10 207
8 15 45
2 9 253
10 8 91
10 14 174
20 19 272
20 3 69
4 7 9
19 12 192
3 5 21
20 1 2...

output:

1

result:

wrong answer 1st lines differ - expected: '651', found: '1'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 10656kb

input:

20 80 10
8 15 24
16 14 128
7 9 8
6 1 12
4 11 273
9 14 238
8 17 155
11 5 220
15 10 132
17 7 10
9 18 1...

output:

0

result:

wrong answer 1st lines differ - expected: '569', found: '0'

Test #3:

score: 0
Wrong Answer
time: 6ms
memory: 10660kb

input:

20 80 10
1 13 196
6 2 133
11 14 193
4 11 148
11 19 21
16 15 84
3 19 201
5 15 286
11 16 161
12 13 296...

output:

5

result:

wrong answer 1st lines differ - expected: '633', found: '5'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 10660kb

input:

20 80 10
5 15 33
9 13 52
9 5 48
8 3 251
6 9 281
8 9 111
18 17 48
8 14 145
19 15 299
4 20 88
6 2 281
...

output:

1

result:

wrong answer 1st lines differ - expected: '596', found: '1'

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 10660kb

input:

20 80 10
6 15 124
7 15 242
6 5 172
11 2 46
3 4 273
2 4 173
7 9 175
9 16 264
17 14 15
16 17 211
8 18 ...

output:

3

result:

wrong answer 1st lines differ - expected: '989', found: '3'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 10660kb

input:

20 80 10
6 5 252
2 20 182
20 14 107
5 15 128
4 10 283
8 17 21
2 17 203
9 4 289
18 4 218
3 15 25
10 9...

output:

0

result:

wrong answer 1st lines differ - expected: '571', found: '0'

Test #7:

score: 0
Wrong Answer
time: 30ms
memory: 13840kb

input:

2000 100000 800
1287 1255 1987
1744 883 836
149 1453 1336
351 1172 1071
850 1465 848
740 1675 863
11...

output:

0

result:

wrong answer 1st lines differ - expected: '6', found: '0'

Test #8:

score: 0
Wrong Answer
time: 37ms
memory: 13848kb

input:

2000 100000 800
540 62 1546
684 1940 1135
506 1341 1784
1850 361 1977
18 140 1635
1651 1916 1907
199...

output:

0

result:

wrong answer 1st lines differ - expected: '57', found: '0'

Test #9:

score: 0
Wrong Answer
time: 28ms
memory: 13836kb

input:

2000 100000 800
1450 642 1197
990 388 1850
1656 809 1402
725 786 1349
613 1059 890
1259 1575 1064
95...

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Test #10:

score: 5
Accepted
time: 39ms
memory: 13860kb

input:

2000 100000 10000000
232 194 5205389
1290 1320 94756446
1596 1172 8604877
1838 1057 38095640
1301 54...

output:

169

result:

ok single line: '169'

Test #11:

score: 5
Accepted
time: 33ms
memory: 13844kb

input:

2000 100000 10000000
1377 361 48147042
1023 1928 5049880
1696 843 14727225
920 1294 58661444
1665 51...

output:

533

result:

ok single line: '533'

Test #12:

score: 0
Wrong Answer
time: 23ms
memory: 13852kb

input:

2000 100000 10000000
23 1840 61297021
1090 1814 98946038
1413 1691 85852947
86 1463 92991569
1268 82...

output:

17

result:

wrong answer 1st lines differ - expected: '230103', found: '17'

Test #13:

score: 0
Wrong Answer
time: 137ms
memory: 22364kb

input:

200000 200000 10000000
163447 52269 827108961
69433 60328 8764874
184517 157379 878957413
2825 13277...

output:

196269199653178

result:

wrong answer 1st lines differ - expected: '98144644196729', found: '196269199653178'

Test #14:

score: 0
Wrong Answer
time: 147ms
memory: 22360kb

input:

200000 200000 10000000
26437 26449 733968315
72457 129890 760533116
45625 117585 453891083
113120 65...

output:

195931765041612

result:

wrong answer 1st lines differ - expected: '97982017911608', found: '195931765041612'

Test #15:

score: 0
Wrong Answer
time: 209ms
memory: 22360kb

input:

200000 200000 10000000
134481 172469 958604013
187505 51187 883335613
78523 97379 748522908
76899 44...

output:

196195811208900

result:

wrong answer 1st lines differ - expected: '98108458217572', found: '196195811208900'

Test #16:

score: 0
Wrong Answer
time: 275ms
memory: 22360kb

input:

200000 200000 10000000
31044 159067 847353551
87451 43252 982699932
138867 5542 154557540
83604 6864...

output:

196303834359815

result:

wrong answer 1st lines differ - expected: '98165693118564', found: '196303834359815'

Test #17:

score: 0
Wrong Answer
time: 273ms
memory: 22360kb

input:

200000 200000 10000000
19846 69397 59750638
19566 101018 183206436
7465 190436 164547218
192600 1650...

output:

196511827199478

result:

wrong answer 1st lines differ - expected: '98270021595856', found: '196511827199478'

Test #18:

score: 0
Wrong Answer
time: 240ms
memory: 22360kb

input:

200000 200000 10000000
75029 14324 856954422
6328 45799 557275111
92416 7355 61760133
58432 149196 6...

output:

196013572153506

result:

wrong answer 1st lines differ - expected: '98016594710576', found: '196013572153506'

Test #19:

score: 0
Wrong Answer
time: 139ms
memory: 22356kb

input:

200000 200000 10000000
50062 13355 435813272
161002 4865 505414563
118169 48194 579627562
139289 413...

output:

196135623311914

result:

wrong answer 1st lines differ - expected: '98085543969676', found: '196135623311914'

Test #20:

score: 0
Wrong Answer
time: 127ms
memory: 22364kb

input:

200000 200000 10000000
5476 97888 999474454
20665 24758 972246854
170123 118973 486801275
114106 174...

output:

195845907671538

result:

wrong answer 1st lines differ - expected: '97937044812669', found: '195845907671538'