QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345175#7883. Takeout DeliveringoathWA 1296ms15664kbC++142.1kb2024-03-06 12:49:362024-03-06 12:49:36

Judging History

你现在查看的是最新测评结果

  • [2024-03-06 12:49:36]
  • 评测
  • 测评结果:WA
  • 用时:1296ms
  • 内存:15664kb
  • [2024-03-06 12:49:36]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e6 + 10;
int dist[N];
int st[N];
int n, m;

int p[N];
struct edge
{
    int a, b ,w ;
    
    bool operator < (const edge &W) const
    {
        return w < W.w;
    }
}edges[N*2];

int find(int x)
{
    if(x != p[x]) p[x] = find(p[x]);
    return p[x];
}


signed main()
{
    cin >> n >> m;
    int res = 0x7f7f7f7f;
    for(int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        //if(x == 1 && y == n) res = min(res, z);
        edges[i] = {x, y, z};
    }
    sort(edges, edges + m);
    for(int i = 1; i <= n; i++) p[i] = i;
    //cout << res << endl;
	std::vector<edge> ans;
	int cnt = 0;
    for(int i = 0; i < m ;i++)
    {
        int a = edges[i].a, b = edges[i].b, w =edges[i].w;
        int pa = find(a), pb = find(b);
        int t = p[pa];
        if(pa != pb) 
        {
            p[pa] = pb;
        }
        int a1 = find(1), a2 = find(n);
        if(a1 == a2)
        {
            ans.push_back(edges[i]);
            p[pa] = t;
            st[i] = 1;
        }
    }
    //cout << ans.size() << endl;
    /*for(int i = 0; i <ans.size(); i++){
    	int a = ans[i].a, b = ans[i].b, w =ans[i].w;
    	cout << a << ' ' << b << ' ' << w << endl;
    }*/
    for(int i = 1; i <= n; i++) p[i] = i;
    
    for(int i = 0; i < m ;i++)
    {	
    	if(st[i]) continue;
        int a = edges[i].a, b = edges[i].b, w =edges[i].w;
        int pa = find(a), pb = find(b);
        int t = p[pa];
        if(pa != pb) 
        {
            p[pa] = pb;
        }
        for(int j = cnt; j < ans.size() ;j++){
        		int sa = ans[j].a, sb = ans[j].b, sw =ans[j].w;
        int psa = find(sa), psb = find(sb);
        t = p[psa];
        if(psa != psb) 
        {
            p[psa] = psb;
        }
        int a1 = find(1), a2 = find(n);
        if(a1 == a2)
        {
            res = min(res, w + sw);
            p[psa] = t;
            cnt++;
        }
        	
        }
    }
    cout << res <<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7724kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 208ms
memory: 14728kb

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:

1999991697

result:

ok 1 number(s): "1999991697"

Test #3:

score: 0
Accepted
time: 1296ms
memory: 15664kb

input:

300000 299999
207226 231742 414945003
84591 210444 175968953
46327 51582 612565723
18773 141119 82562646
76139 286963 762958587
131867 224820 928900783
215240 216181 405340417
144725 290878 195350550
267216 268752 846015171
31413 255927 389339642
45219 147512 489502910
113391 215402 555706684
53359 ...

output:

1989898633

result:

ok 1 number(s): "1989898633"

Test #4:

score: -100
Wrong Answer
time: 165ms
memory: 12304kb

input:

300000 299999
1 118488 989720257
1 181002 810258689
1 254222 172925351
1 176703 737330574
1 218306 941887568
1 105741 645573853
1 188490 794789787
1 273997 91455946
1 214929 293300204
1 127289 600097406
1 30589 330284120
1 128954 532459734
1 163729 627033607
1 24073 718818252
1 41571 755054850
1 560...

output:

725566197

result:

wrong answer 1st numbers differ - expected: '725564985', found: '725566197'