QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91987 | #4502. Flowery Trails | meliodas | WA | 112ms | 7360kb | C++14 | 3.6kb | 2023-03-30 05:08:33 | 2023-03-30 05:08:34 |
Judging History
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;
}
else if(auxCost + weight == cost[vertexAd]){
res.push_back(vertex);
re+=recar;
}
}
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: 0ms
memory: 3772kb
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: 3784kb
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: -100
Wrong Answer
time: 112ms
memory: 7360kb
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:
1994
result:
wrong answer 1st lines differ - expected: '1996', found: '1994'