QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#18068 | #2178. Robot | _silhouette_# | 0 | 1677ms | 65792kb | C++ | 1.7kb | 2022-01-16 09:46:30 | 2022-05-04 17:01:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e5,Max_M=1e5;
const long long Inf=1e18;
int n,m,Num,lin[Max_N+5];
long long sum[Max_M+5];
map<int,long long> dis[Max_N+5],vis[Max_N+5];
struct Edge_fir{ int u,v,c,p; } E[Max_M+5];
vector<int> a[Max_N+5];
priority_queue< pair< long long, pair<int,int> > > Q;
struct Edge{
int Next,Id,c;
long long val;
} e[Max_M*4+5];
void Insert(int x,int y,int c,long long w){
e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y; e[Num].c=c; e[Num].val=w;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d%d%d",&E[i].u,&E[i].v,&E[i].c,&E[i].p);
a[E[i].u].push_back(i),a[E[i].v].push_back(i);
}
for(int x=1;x<=n;x++){
dis[x][-1]=Inf;
for(int i=0;i<a[x].size();i++)
sum[E[a[x][i]].c]+=E[a[x][i]].p,
dis[x==E[a[x][i]].u?E[a[x][i]].v:E[a[x][i]].u][a[x][i]]=Inf;
for(int i=0;i<a[x].size();i++)
Insert(x,x==E[a[x][i]].u?E[a[x][i]].v:E[a[x][i]].u,a[x][i],E[a[x][i]].p),
Insert(x,x==E[a[x][i]].u?E[a[x][i]].v:E[a[x][i]].u,-1,sum[E[a[x][i]].c]-E[a[x][i]].p);
for(int i=0;i<a[x].size();i++)
sum[E[a[x][i]].c]-=E[a[x][i]].p;
}
Q.push(make_pair(0,make_pair(1,-1)));
dis[1][-1]=0;
for(;Q.size();){
int x=Q.top().second.first;
int c=Q.top().second.second; Q.pop();
if(vis[x][c]) continue; vis[x][c]=1;
for(int i=lin[x];i;i=e[i].Next){
if(c!=-1&&e[i].c!=-1&&E[c].c==E[e[i].c].c)
dis[e[i].Id][e[i].c]=min(dis[e[i].Id][e[i].c],dis[x][c]+e[i].val-E[c].p);
else dis[e[i].Id][e[i].c]=min(dis[e[i].Id][e[i].c],dis[x][c]+e[i].val);
Q.push(make_pair(-dis[e[i].Id][e[i].c],make_pair(e[i].Id,e[i].c)));
}
}
long long ans=dis[n][-1];
for(int i=lin[n];i;i=e[i].Next)
ans=min(ans,dis[n][e[i].c]);
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 34
Accepted
time: 3ms
memory: 18200kb
input:
2 1 1 2 1 10
output:
0
result:
ok single line: '0'
Test #2:
score: -34
Wrong Answer
time: 2ms
memory: 18068kb
input:
8 1 5 6 1 7
output:
1000000000000000000
result:
wrong answer 1st lines differ - expected: '-1', found: '1000000000000000000'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 1677ms
memory: 65792kb
input:
25437 78923 921 9998 30945 1 5452 13736 24464 1 11746 24238 24464 1 10875 12958 24464 1 12267 20617 30945 1 3738 16549 35589 1 16223 16940 35589 1 1303 23059 24464 1 12424 21853 24464 1 11198 20674 35589 1 15645 19099 30945 1 8860 9441 24464 1 3609 15160 35589 1 22638 23472 24464 1 766 8991 35589 1 ...
output:
1
result:
wrong answer 1st lines differ - expected: '5', found: '1'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%