QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50927 | #4437. Link with Running | zzxzzx123 | WA | 707ms | 15512kb | C++17 | 1.6kb | 2022-09-29 18:29:24 | 2022-09-29 18:29:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<ll,ll>
const int N=3e5+50;
int h[N],e[N],ne[N],idx,vis[N],d[N],cnt;
ll w[N],val[N];
void add(int u,int v,ll c,ll d){
e[idx]=v,ne[idx]=h[u],w[idx]=c,val[idx]=d,h[u]=idx++;
}
struct node{
int u;
ll e,p;
bool operator<(const node& a)const {
if(e!=a.e){
return e>a.e;
}
//p大的在前面
return p<a.p;
}
};
int n,m;
int id[N],be[N];
pii ans[N];
void dij()
{
for(int j=1;j<=n;j++)
{
//这个是拓扑的序列
int u=be[j];
for(int i=h[u];~i;i=ne[i]){
int v=e[i];
if(ans[v].first>ans[u].first+w[i])
{
ans[v].first=ans[u].first+w[i];
ans[v].second=ans[u].second+val[i];
continue;
}
if(ans[v].first==(ans[u].first+w[i])){
ans[v].second=max(ans[v].second,ans[u].second+val[i]);
continue;
}
}
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(h,-1,sizeof h);
memset(d,0,sizeof d);
idx=0;
scanf("%d%d",&n,&m);
for(int i=2;i<=n;i++){
ans[i].first=1e17;
ans[i].second=0;
}
for(int i=1;i<=m;i++)
{
int u,v;
ll e,p;//如果是没有的点的话提前进行结束
scanf("%d%d%lld%lld",&u,&v,&e,&p);
d[v]++;
add(u,v,e,p);
}//先选择补丢弃环
cnt=0;
queue<int>q;
for(int i=1;i<=n;i++){
if(!d[i])
{
q.push(i);
}
}
while(!q.empty()){
int u=q.front();
q.pop();
id[u]=++cnt;
be[cnt]=u;
for(int i=h[u];~i;i=ne[i]){
int v=e[i];
d[v]--;
if(!d[v]){
q.push(v);
}
}
}
dij();
printf("%lld %lld\n",ans[n].first,ans[n].second);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 707ms
memory: 15512kb
input:
12 100000 200000 1 2 838279516 902819511 1 3 293478832 513256010 2 4 682688353 204481674 2 5 360092507 651108247 5 6 519851939 323803002 6 7 675439277 205804465 7 8 419167205 386168059 6 9 140767493 382483305 9 10 558115401 613738466 9 11 902235661 744659643 9 12 851394758 1720015 12 13 635355827 46...
output:
100000000000000000 0 100000000000000000 0 2522027 438209666288 100000000000000000 0 249512452 24966236662852 100000000000000000 1483377941 100000000000000000 1290390554 0 1000000000 100000000000000000 0 100000000000000000 1 100000000000000000 0 100000000000000000 0
result:
wrong answer 1st lines differ - expected: '5927443549 11285847934', found: '100000000000000000 0'