QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715614#8136. Rebellious Edgeucup-team4074#WA 35ms5692kbC++171.1kb2024-11-06 12:47:082024-11-06 12:47:09

Judging History

This is the latest submission verdict.

  • [2024-11-06 12:47:09]
  • Judged
  • Verdict: WA
  • Time: 35ms
  • Memory: 5692kb
  • [2024-11-06 12:47:08]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

void solve();

signed main() {
    fast
    int t = 1;
    cin >> t;
    while (t--) solve();
}
const int maxn=500010;
struct A{int x,y,z;};
A e[maxn];
int v[maxn];
int n,m,id=0;
void add(int x,int y,int z)
{
    e[++id]={x,y,z};
}
bool comp(A p,A q)
{
    return p.x<q.x;
}
int ch()
{
    int ans=0;
    sort(e+1,e+id+1,comp);
    for(int i=1;i<=m;i++)
    {
       if(!v[e[i].y])
       {
           v[e[i].y]=1;
           ans+=e[i].z;
       }
    }
    return ans;
}
void solve() {
    id=0;
    cin>>n>>m;
    int xi,yi,zi;
    for(int i=1;i<=n;i++)
    {
        v[i]=0;
    }
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(x<y)add(x,y,z);
        else
        {
            xi=x;
            yi=y;
            zi=z;
        }
    }
    int ans=ch();
    for(int i=1;i<=n;i++)v[i]=0;
    v[yi]=1;
    ans=min(ans,zi+ch());
    cout<<ans<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5672kb

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: 35ms
memory: 5692kb

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:

1291015520
1843815446
1534956009
577225018
1366795927
1077788279
2567005573
1648624744
1034153425
793861088
1422621111
1051598350
1548359945
1636369163
1070967047
1899616226
1610587072
572354390
960978736
984886788
1696503797
1002892611
1969660290
1454394728
1863906917
977157479
2097949028
114373309...

result:

wrong answer 2nd numbers differ - expected: '1530420294', found: '1843815446'