QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91999#4502. Flowery TrailsmeliodasWA 153ms10424kbC++143.7kb2023-03-30 07:54:522023-03-30 07:54:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 07:54:55]
  • 评测
  • 测评结果:WA
  • 用时:153ms
  • 内存:10424kb
  • [2023-03-30 07:54:52]
  • 提交

answer

//https://onlinejudge.org/external/128/12878.pdf
//12878

#include<climits>
#include<vector>
#include<queue>
#include<tuple>
#include<iostream>
#include<algorithm>

using namespace std;

int points, re;
vector<int>pre(10000);
vector<int>canti(10000);
vector<int>cost(10000);

void initialize(int init){

    int i;

    for(i = 0; i<points; i++){

        cost[i] = INT_MAX;
        pre[i] = -1;
        canti[i] = 0;
    }

    cost[init] = 0;
}

void dijkstra(int init, vector<vector<tuple<int, int, int>>>&graph, vector<int>&res){

    int weight, auxCost, vertex, vertexAd, i, recar;
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>>cola;

    initialize(init);
    cola.push(make_tuple(init, 0, 0));
    

    while(!cola.empty()){

        vertex = get<0>(cola.top());
        auxCost = get<1>(cola.top());
        recar = get<2>(cola.top());

        cola.pop();
        //cout<<vertex<<" "<<auxCost<<endl;
    
        if(auxCost == cost[vertex]){

            for(i = 0; i<graph[vertex].size(); i++){

                vertexAd = get<0>(graph[vertex][i]);
                weight = get<1>(graph[vertex][i]);
                
                if(vertexAd == points-1){

                    if(auxCost + weight < cost[vertexAd]){
                        res = {vertex};
                        re = recar + get<2>(graph[vertex][i]);
                    }

                    else if(auxCost + weight == cost[vertexAd]){
                        res.push_back(vertex);
                        re+=recar + get<2>(graph[vertex][i]);
                    }

                }
                if(auxCost != INT_MAX && auxCost + weight < cost[vertexAd]){
                    
                    canti[vertexAd] = 1;
                    pre[vertexAd] = vertex;
                    cost[vertexAd] = auxCost + weight;
                    cola.push(make_tuple(vertexAd, cost[vertexAd], recar+get<2>(graph[vertex][i])));

                } 

                else if(auxCost != INT_MAX && auxCost + weight == cost[vertexAd]){
                    
                    canti[vertexAd]+=1;
                } 
            }
        }
    }
    
}

int main(){

    int trails, length, a, b, size, counter, i;

    while(scanf("%i %i", &points, &trails) != EOF){

        vector<vector<tuple<int, int, int>>>graph(points);
        vector<tuple<int, int, int>>::iterator it;
        vector<tuple<int, int, int>>::iterator it2;  
        vector<int>res;
        vector<int>visits(points, 0);

        re = 0;
        counter = 0;

        while(trails--){

            scanf("%i %i %i", &a, &b, &size);
            
            for(it2 = graph[b].begin(); it2 != graph[b].end() && (get<0>(*it2) != a || get<1>(*it2) != size); it2++);
            for(it = graph[a].begin(); it != graph[a].end() && (get<0>(*it) != b || get<1>(*it) != size); it++);

            if(it != graph[a].end()) get<2>(*it)+=size, get<2>(*it2)+=size;

            else graph[a].push_back(make_tuple(b, size, 0)), graph[b].push_back(make_tuple(a, size, 0));

        }

        dijkstra(0, graph, res);

        for(i = 0; i<res.size(); i++){

            a = res[i]; 
            int mult = 1;
            counter+= cost[points-1] - cost[a];

            while(pre[a] != -1 && !visits[a]){
                
                if(canti[a] > mult) mult = canti[a];
                
               /*  cout<<canti[pre[a]]<<" "<<a<<endl; */

                counter+= (cost[a] - cost[pre[a]]) * mult;
                visits[a] = 1;
                a = pre[a];
            }
        }

        printf("%i\n", (counter + re) * 2);
    }

}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3840kb

input:

10 15
0 1 580
1 4 90
1 4 90
4 9 250
4 2 510
2 7 600
7 3 200
3 3 380
3 0 150
0 3 100
7 8 500
7 9 620
9 6 510
6 5 145
5 9 160

output:

3860

result:

ok single line: '3860'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3788kb

input:

4 7
0 1 1
0 2 2
0 3 10
0 3 3
1 3 2
2 3 1
1 1 1

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 96ms
memory: 7364kb

input:

500 249500
0 1 1
0 1 1
0 2 1000
0 2 1000
0 3 1000
0 3 1000
0 4 1000
0 4 1000
0 5 1000
0 5 1000
0 6 1000
0 6 1000
0 7 1000
0 7 1000
0 8 1000
0 8 1000
0 9 1000
0 9 1000
0 10 1000
0 10 1000
0 11 1000
0 11 1000
0 12 1000
0 12 1000
0 13 1000
0 13 1000
0 14 1000
0 14 1000
0 15 1000
0 15 1000
0 16 1000
0 1...

output:

1996

result:

ok single line: '1996'

Test #4:

score: 0
Accepted
time: 153ms
memory: 10424kb

input:

500 249500
0 1 1
0 1 10
0 2 999
0 2 1000
0 3 999
0 3 1000
0 4 999
0 4 1000
0 5 999
0 5 1000
0 6 999
0 6 1000
0 7 999
0 7 1000
0 8 999
0 8 1000
0 9 999
0 9 1000
0 10 999
0 10 1000
0 11 999
0 11 1000
0 12 999
0 12 1000
0 13 999
0 13 1000
0 14 999
0 14 1000
0 15 999
0 15 1000
0 16 999
0 16 1000
0 17 99...

output:

998

result:

ok single line: '998'

Test #5:

score: -100
Wrong Answer
time: 73ms
memory: 4188kb

input:

4096 245680
0 1 1
0 2 1
1 3 1
1 4 1
2 5 1
2 6 1
3 7 1
3 8 1
4 9 1
4 10 1
5 11 1
5 12 1
6 13 1
6 14 1
7 15 1
7 16 1
8 17 1
8 18 1
9 19 1
9 20 1
10 21 1
10 22 1
11 23 1
11 24 1
12 25 1
12 26 1
13 27 1
13 28 1
14 29 1
14 30 1
15 31 1
15 32 1
16 33 1
16 34 1
17 35 1
17 36 1
18 37 1
18 38 1
19 39 1
19 40...

output:

1929212

result:

wrong answer 1st lines differ - expected: '491360', found: '1929212'