QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279893 | #7871. 命运 | zhouhuanyi | 0 | 1ms | 7728kb | C++20 | 1.8kb | 2023-12-09 11:28:40 | 2023-12-09 11:28:41 |
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 500000
using namespace std;
const int inf=(int)(1e9);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
int x,y,z,cl;
bool operator < (const reads &t)const
{
return z>t.z;
}
};
reads ed[N+1];
int n,m,k,s,rt[N+1];
bool used[N+1];
long long ans;
int find(int x)
{
if (rt[x]==x) return x;
return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
rt[x]=y;
return;
}
bool check(int x)
{
int l=0,r=0;
for (int i=1;i<=n;++i) rt[i]=i;
for (int i=1;i<=x-1;++i)
if (used[i]&&find(ed[i].x)!=find(ed[i].y))
unionn(find(ed[i].x),find(ed[i].y));
for (int i=x;i<=m;++i)
if (!ed[i].cl&&find(ed[i].x)!=find(ed[i].y))
unionn(find(ed[i].x),find(ed[i].y));
for (int i=x;i<=m;++i)
if (ed[i].cl&&find(ed[i].x)!=find(ed[i].y))
l++,unionn(find(ed[i].x),find(ed[i].y));
for (int i=1;i<=n;++i) rt[i]=i;
for (int i=1;i<=x-1;++i)
if (used[i]&&find(ed[i].x)!=find(ed[i].y))
unionn(find(ed[i].x),find(ed[i].y));
for (int i=x;i<=m;++i)
if (ed[i].cl&&find(ed[i].x)!=find(ed[i].y))
r++,unionn(find(ed[i].x),find(ed[i].y));
for (int i=x;i<=m;++i)
if (!ed[i].cl&&find(ed[i].x)!=find(ed[i].y))
unionn(find(ed[i].x),find(ed[i].y));
for (int i=1;i<=n;++i)
if (find(i)!=find(1))
return 0;
return k<=r;
}
int main()
{
n=read(),m=read(),k=read(),s=read();
for (int i=1;i<=m;++i)
{
ed[i].x=read(),ed[i].y=read(),ed[i].z=read();
if (ed[i].x==s||ed[i].y==s) ed[i].cl=1;
}
if (!check(1))
{
puts("nonnondayo");
return 0;
}
sort(ed+1,ed+m+1);
for (int i=1;i<=m;++i)
if (!check(i+1))
ans+=ed[i].z,used[i]=1,k-=ed[i].cl;
printf("%lld\n",ans);
return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
49277 49276 1 49277 1 2 2000 2 3 3000 2 4 4000 3 5 5000 3 6 6000 4 7 7000 1 8 8000 7 9 9000 1 10 10000 5 11 11000 4 12 12000 3 13 13000 13 14 14000 1 15 15000 7 16 16000 11 17 17000 2 18 18000 10 19 19000 6 20 20000 4 21 21000 17 22 22000 1 23 23000 14 24 24000 4 25 25000 16 26 26000 15 27 27000 9 2...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 10
Accepted
time: 1ms
memory: 7728kb
input:
21 20 2 21 1 2 18581 1 3 9620 2 4 4362 1 5 7702 5 6 17435 4 7 11679 3 8 14832 1 9 15073 2 10 6595 5 11 19676 11 12 16943 12 13 5268 5 14 20262 8 15 8192 7 16 12340 7 17 1437 7 18 3064 2 19 10437 12 20 2882 19 21 13483
output:
nonnondayo
result:
ok single line: 'nonnondayo'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5820kb
input:
10 20 4 3 1 2 18247 2 3 9041 2 4 4031 2 5 7363 3 6 17172 1 7 11014 6 8 14781 8 9 15347 8 10 6598 5 9 19331 3 10 16523 10 6 5732 2 3 20357 6 9 8827 10 3 12864 6 3 1551 5 6 3932 3 1 10223 9 3 2296 8 5 13620
output:
54418
result:
ok single line: '54418'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5772kb
input:
10 20 6 10 1 2 18401 2 3 9843 3 4 4219 4 5 7552 4 6 17751 4 7 11318 5 8 14774 8 9 15541 5 10 6928 6 10 19860 10 5 16699 5 8 5937 5 2 20611 1 8 8077 10 1 12386 9 4 1663 9 10 3910 1 9 10401 7 10 2383 2 9 13681
output:
nonnondayo
result:
ok single line: 'nonnondayo'
Test #8:
score: -10
Wrong Answer
time: 1ms
memory: 5836kb
input:
10 20 1 10 1 2 18853 2 3 9034 3 4 4069 3 5 7743 3 6 17122 6 7 11715 2 8 14814 1 9 15011 7 10 6248 6 8 19400 7 3 16354 6 8 5249 7 8 20701 5 10 8079 10 5 12570 7 10 1006 8 3 3814 5 10 10753 5 9 2310 8 6 13123
output:
56315
result:
wrong answer 1st lines differ - expected: '59951', found: '56315'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
49996 50165 184 1 3 2 123052595 4 3 96661399 5 2 21916499 6 3 110026337 7 6 37432710 8 2 38560107 9 8 83209370 10 8 80352229 11 2 88957425 12 7 65449321 13 5 38238243 14 5 90153912 15 11 30810953 16 3 96492912 17 13 112885611 18 15 87190336 19 9 91182003 20 2 107304872 21 6 101440738 22 13 120601711...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%