QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317176 | #7343. Bicycle Race | Terk | WA | 4ms | 18080kb | C++14 | 1.7kb | 2024-01-28 17:11:43 | 2024-01-28 17:11:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,m,ans=-1;
int u[N],v[N],w[N],deg[N],vis[N];
struct node{
int to,w;
};
vector<node> E[N],e[N];
struct nn{
int x,y,w;
}Rem[N];
int cmp(nn a,nn b){
return a.x<b.x;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>u[i]>>v[i]>>w[i];
E[u[i]].push_back({v[i],w[i]});
E[v[i]].push_back({u[i],w[i]});
deg[u[i]]++,deg[v[i]]++;
}
for(int i=1;i<=m;i++){
if(deg[u[i]]>deg[v[i]]||(deg[u[i]]==deg[v[i]]&&u[i]>v[i]))swap(u[i],v[i]);
e[u[i]].push_back({v[i],w[i]});
}
for(int i=1;i<=n;i++){
int cnt=0,tp1=0,tp2=0,tp3=0,val1=-1e9,val2=-1e9,val3=-1e9;
for(auto j:E[i]) vis[j.to]=j.w;
for(auto j:E[i]){
int x=j.to;
for(auto k:e[x]){
int y=k.to;
if(vis[y]) Rem[++cnt]={x,y,j.w+k.w+vis[y]};
}
}
for(auto j:E[i]) vis[j.to]=0;
sort(Rem+1,Rem+1+cnt,cmp);
for(int j=1;j<=cnt;){
int t=j;
while(1){
if(Rem[j].x!=tp1&&Rem[j].y!=tp1) ans=max(ans,Rem[j].w+val1);
if(Rem[j].x!=tp2&&Rem[j].y!=tp2) ans=max(ans,Rem[j].w+val2);
if(Rem[j].x!=tp3&&Rem[j].y!=tp3) ans=max(ans,Rem[j].w+val3);
if(Rem[j].x!=Rem[j+1].x) break;
j++;
}
swap(j,t);
while(j<=t){
if(Rem[j].y==tp1) val1=max(val1,Rem[j].w);
else if(Rem[j].y==tp2) val2=max(val2,Rem[j].w);
else if(Rem[j].y==tp3) val3=max(val3,Rem[j].w);
else if(Rem[j].w>tp1){
tp3=tp2,val3=val2;
tp2=tp1,val2=val1;
tp1=Rem[j].y,val1=Rem[j].w;
}
else if(Rem[j].w>tp2){
tp3=tp2,val3=val2;
tp2=Rem[j].y,val2=Rem[j].w;
}
else if(Rem[j].w>tp3) tp3=Rem[j].y,val3=Rem[j].w;
j++;
}
}
}
cout<<ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 18044kb
input:
6 9 1 2 3 2 3 1 3 4 2 4 5 1 3 5 7 2 5 2 1 5 3 4 6 2 5 6 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 18080kb
input:
6 6 1 3 2 1 2 2 2 3 4 3 4 1 3 6 6 1 4 8
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 18036kb
input:
5 6 1 4 2 1 3 6 5 2 10 3 2 4 4 2 1 5 4 7
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 15908kb
input:
5 10 2 1 9 3 1 4 3 2 3 4 1 5 4 2 9 4 3 9 5 1 5 5 2 6 5 3 10 5 4 1
output:
43
result:
ok 1 number(s): "43"
Test #5:
score: 0
Accepted
time: 0ms
memory: 17952kb
input:
5 10 2 1 9 3 1 8 3 2 8 4 1 1 4 2 2 4 3 8 5 1 10 5 2 1 5 3 10 5 4 3
output:
46
result:
ok 1 number(s): "46"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 17944kb
input:
5 9 1 3 4 4 1 10 1 5 9 5 2 9 3 5 9 2 3 7 5 4 1 2 1 7 2 4 1
output:
47
result:
wrong answer 1st numbers differ - expected: '45', found: '47'