ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213061 | #2675. Road Reform | nullptr_qwq | 100 | 789ms | 4272kb | C++11 | 5.2kb | 2024-11-09 18:44:13 | 2024-11-09 23:02:47 |
answer
// 私は猫です
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
ll read(){
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,maxn=500005;
struct node{
int u,v,w;
bool operator<(const node &rhs)const{
if(w^rhs.w)return w<rhs.w;
if(u^rhs.u)return u<rhs.u;
return v<rhs.v;
}
}e[maxn];
int fa[maxn],n,m,k,res;
int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]); }
void solve(){
cin>>n>>m>>k;
F(i,1,m)cin>>e[i].u>>e[i].v>>e[i].w;
F(i,1,n)fa[i]=i;
sort(e+1,e+m+1);
int qwq=0;
ll ans=0;
F(i,1,m){
int u=e[i].u,v=e[i].v,w=e[i].w;
if(find(u)==find(v))continue;
fa[find(u)]=find(v),chkmax(qwq,w);
if(qwq>k)ans+=qwq-k;
}
if(qwq<k){
ans=infll;
F(i,1,m)chkmin(ans,1ll*abs(k-e[i].w));
}
cout<<ans;
}
signed main(){
int zsy=1;
F(____,1,zsy)solve();
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1144kb
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:
651
result:
ok single line: '651'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1144kb
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:
569
result:
ok single line: '569'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1144kb
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:
633
result:
ok single line: '633'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1148kb
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:
596
result:
ok single line: '596'
Test #5:
score: 5
Accepted
time: 0ms
memory: 1148kb
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:
989
result:
ok single line: '989'
Test #6:
score: 5
Accepted
time: 1ms
memory: 1144kb
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:
571
result:
ok single line: '571'
Test #7:
score: 5
Accepted
time: 20ms
memory: 2324kb
input:
2000 100000 800 1287 1255 1987 1744 883 836 149 1453 1336 351 1172 1071 850 1465 848 740 1675 863 11...
output:
6
result:
ok single line: '6'
Test #8:
score: 5
Accepted
time: 19ms
memory: 2328kb
input:
2000 100000 800 540 62 1546 684 1940 1135 506 1341 1784 1850 361 1977 18 140 1635 1651 1916 1907 199...
output:
57
result:
ok single line: '57'
Test #9:
score: 5
Accepted
time: 25ms
memory: 2324kb
input:
2000 100000 800 1450 642 1197 990 388 1850 1656 809 1402 725 786 1349 613 1059 890 1259 1575 1064 95...
output:
1
result:
ok single line: '1'
Test #10:
score: 5
Accepted
time: 34ms
memory: 2324kb
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: 29ms
memory: 2324kb
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: 5
Accepted
time: 33ms
memory: 2324kb
input:
2000 100000 10000000 23 1840 61297021 1090 1814 98946038 1413 1691 85852947 86 1463 92991569 1268 82...
output:
230103
result:
ok single line: '230103'
Test #13:
score: 5
Accepted
time: 91ms
memory: 4268kb
input:
200000 200000 10000000 163447 52269 827108961 69433 60328 8764874 184517 157379 878957413 2825 13277...
output:
98144644196729
result:
ok single line: '98144644196729'
Test #14:
score: 5
Accepted
time: 108ms
memory: 4272kb
input:
200000 200000 10000000 26437 26449 733968315 72457 129890 760533116 45625 117585 453891083 113120 65...
output:
97982017911608
result:
ok single line: '97982017911608'
Test #15:
score: 5
Accepted
time: 89ms
memory: 4268kb
input:
200000 200000 10000000 134481 172469 958604013 187505 51187 883335613 78523 97379 748522908 76899 44...
output:
98108458217572
result:
ok single line: '98108458217572'
Test #16:
score: 5
Accepted
time: 91ms
memory: 4268kb
input:
200000 200000 10000000 31044 159067 847353551 87451 43252 982699932 138867 5542 154557540 83604 6864...
output:
98165693118564
result:
ok single line: '98165693118564'
Test #17:
score: 5
Accepted
time: 72ms
memory: 4268kb
input:
200000 200000 10000000 19846 69397 59750638 19566 101018 183206436 7465 190436 164547218 192600 1650...
output:
98270021595856
result:
ok single line: '98270021595856'
Test #18:
score: 5
Accepted
time: 63ms
memory: 4272kb
input:
200000 200000 10000000 75029 14324 856954422 6328 45799 557275111 92416 7355 61760133 58432 149196 6...
output:
98016594710576
result:
ok single line: '98016594710576'
Test #19:
score: 5
Accepted
time: 58ms
memory: 4268kb
input:
200000 200000 10000000 50062 13355 435813272 161002 4865 505414563 118169 48194 579627562 139289 413...
output:
98085543969676
result:
ok single line: '98085543969676'
Test #20:
score: 5
Accepted
time: 56ms
memory: 4272kb
input:
200000 200000 10000000 5476 97888 999474454 20665 24758 972246854 170123 118973 486801275 114106 174...
output:
97937044812669
result:
ok single line: '97937044812669'