QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#663057 | #4272. Phone Plans | SimonLJK | 0 | 208ms | 82784kb | C++14 | 2.0kb | 2024-10-21 12:26:48 | 2024-10-21 12:26:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+999;
int n,m[2];
ll k,cnt[N],now;
struct edge{
int u,v,w;
bool operator <(const edge&A) const{
return w<A.w;
}
}e[2][N];
vector<int> bel[N],mer[N];
unordered_map<int,int> mp[N];
void ins(int u,int col){
mp[u][0]++; mp[u][col]++;
now+=mp[u][0]-mp[u][col];
return;
}
void era(int u,int col){
mp[u][0]--; mp[u][col]--;
now-=mp[u][0]-mp[u][col];
}
int id[N],f[N],sz[N];
int find(int x){
if(id[x]==x) return x;
return id[x]=find(id[x]);
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
int u,v,w;
cin>>n>>m[0]>>m[1]>>k;
for(int i=1;i<=m[0];i++)
cin>>e[0][i].u>>e[0][i].v>>e[0][i].w;
sort(e[0]+1,e[0]+m[0]+1);
for(int i=1;i<=m[1];i++)
cin>>e[1][i].u>>e[1][i].v>>e[1][i].w;
sort(e[1]+1,e[1]+m[1]+1);
for(int i=1;i<=n;i++){
id[i]=i,sz[i]=1;
bel[i].push_back(i);
}
for(int i=1;i<=m[0];i++){
cnt[i]=cnt[i-1];
u=e[0][i].u; v=e[0][i].v;
u=find(u); v=find(v);
if(u==v) continue;
if(sz[u]<sz[v]) swap(u,v);
for(int j=0;j<sz[v];j++)
bel[u].push_back(bel[v][j]);
swap(mer[i],bel[v]);
cnt[i]+=1ll*sz[u]*sz[v];
id[v]=u; sz[u]+=sz[v];
}
for(int i=1;i<=n;i++){
f[i]=id[i];
id[i]=i; sz[i]=1;
bel[i].resize(1); bel[i][0]=i;
mp[i][0]=mp[i][f[i]]=1;
}
int ans=2e9+1;
for(int i=m[0],j=0;i>=0;i--){
while(cnt[i]+now<k){
if(j==m[1]){j++; break; }
j++; u=e[1][j].u; v=e[1][j].v;
u=find(u); v=find(v);
if(u==v) continue;
if(sz[u]<sz[v]) swap(u,v);
bel[u].resize(sz[u]+sz[v]);
for(int q=0;q<sz[v];q++){
bel[u].push_back(bel[v][q]);
era(v,f[bel[v][q]]); ins(u,f[bel[v][q]]);
}
id[v]=u; sz[u]+=sz[v];
}
if(j>m[1]) break;
ans=min(ans,e[0][i].w+e[1][j].w);
for(int j=0;j<mer[i].size();j++){
era(find(mer[i][j]),f[mer[i][j]]);
f[mer[i][j]]=mer[i][0];
ins(find(mer[i][j]),f[mer[i][j]]);
}
}
if(ans==2e9+1) cout<<-1;
else cout<<ans;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 6
Accepted
time: 0ms
memory: 28248kb
input:
6 4 4 9 1 2 1 2 3 2 1 4 3 3 4 4 5 6 40 1 5 30 2 6 20 3 6 10
output:
33
result:
ok single line: '33'
Test #2:
score: 6
Accepted
time: 3ms
memory: 26068kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #3:
score: 6
Accepted
time: 3ms
memory: 26272kb
input:
2 0 0 1
output:
-1
result:
ok single line: '-1'
Test #4:
score: 6
Accepted
time: 8ms
memory: 30232kb
input:
2 10 10 1 1 1 915886339 2 2 430624192 1 1 879808770 1 2 577221915 1 1 439429731 1 2 304911826 1 1 148009333 1 2 51122687 1 1 558282772 1 2 421196385 2 1 436692145 1 2 654020563 2 2 162573477 2 2 989531779 1 1 646687051 2 2 549037477 2 2 699532275 1 1 679375858 2 1 83352965 2 1 415698228
output:
51122687
result:
ok single line: '51122687'
Test #5:
score: 6
Accepted
time: 3ms
memory: 28172kb
input:
2 10 10 1 1 1 1000000000 1 2 1000000000 2 2 1000000000 2 1 1000000000 1 2 1000000000 1 1 1000000000 1 2 1000000000 2 2 1000000000 1 2 1000000000 1 2 1000000000 2 1 1000000000 1 2 1000000000 2 1 1000000000 2 2 1000000000 1 2 1000000000 2 2 1000000000 1 1 1000000000 1 1 1000000000 2 2 1000000000 1 2 1...
output:
1000000000
result:
ok single line: '1000000000'
Test #6:
score: 0
Wrong Answer
time: 42ms
memory: 28892kb
input:
2000 0 200000 1199833 636 1231 120395621 689 1640 497332138 1861 1980 798839749 560 1283 560726905 1332 328 431171189 1203 1764 466367210 1102 347 317109768 1462 789 761470540 350 1093 551905741 1718 1047 548650524 51 546 56733461 58 1519 744207013 826 956 943929583 1969 207 238061756 99 47 99683567...
output:
10105753
result:
wrong answer 1st lines differ - expected: '9768257', found: '10105753'
Subtask #2:
score: 0
Wrong Answer
Test #53:
score: 0
Wrong Answer
time: 208ms
memory: 82784kb
input:
200000 100000 100000 7628995 23677 113459 839167193 165893 15365 669621527 26287 109671 214795757 156871 136723 522277985 9957 100463 806718116 104783 161385 156110975 184577 92225 545172629 57373 130083 980035338 167231 49597 919886451 115601 24325 717233004 99413 141311 737488449 83437 62759 76873...
output:
508471502
result:
wrong answer 1st lines differ - expected: '502149991', found: '508471502'
Subtask #3:
score: 0
Wrong Answer
Test #103:
score: 6
Accepted
time: 7ms
memory: 26068kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #104:
score: 6
Accepted
time: 3ms
memory: 26340kb
input:
2 0 0 1
output:
-1
result:
ok single line: '-1'
Test #105:
score: 6
Accepted
time: 38ms
memory: 30232kb
input:
2 10 200000 1 2 1 319832429 1 1 412617159 2 1 337734185 1 2 674652880 1 2 454610992 2 2 688717944 1 1 189208056 2 2 951221780 1 2 594191431 2 2 87592160 1 2 833491749 2 2 732961971 2 1 575969648 2 2 268359887 2 1 436382098 1 2 514959278 1 2 305446083 1 2 365989813 1 2 296840111 1 1 541558213 1 1 497...
output:
10104
result:
ok single line: '10104'
Test #106:
score: 6
Accepted
time: 28ms
memory: 28492kb
input:
2 10 200000 1 1 1 1000000000 1 1 1000000000 1 2 1000000000 1 2 1000000000 1 2 1000000000 1 1 1000000000 2 1 1000000000 2 2 1000000000 2 2 1000000000 2 2 1000000000 1 1 1000000000 1 2 1000000000 1 1 1000000000 2 1 1000000000 1 1 1000000000 1 1 1000000000 2 1 1000000000 1 1 1000000000 2 2 1000000000 2...
output:
1000000000
result:
ok single line: '1000000000'
Test #107:
score: 0
Wrong Answer
time: 86ms
memory: 72196kb
input:
200000 10 200000 17900 199675 76237 290240030 50211 6922 761990536 92097 120746 607490 192856 130409 616541101 50427 80049 330957286 129588 180294 466199684 8674 110653 155297749 91380 156344 798960399 102127 40858 801752583 94673 105892 152356242 185676 6183 263664373 169026 112948 812501808 93517 ...
output:
76562165
result:
wrong answer 1st lines differ - expected: '75425485', found: '76562165'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%