QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50930 | #4437. Link with Running | zzxzzx123 | WA | 722ms | 18152kb | C++17 | 1.8kb | 2022-09-29 18:53:07 | 2022-09-29 18:53:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<ll,ll>
const int N=3e5+50;
const ll inf=1e17;
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];
if(ans[u].first==inf) continue;
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=inf;
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;
q.push(1);
for(int i=2;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(v==1) continue;
if(!d[v]){
q.push(v);
}
}
}
cout<<(cnt==n)<<endl;
dij();
printf("%lld %lld\n",ans[n].first,ans[n].second);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 722ms
memory: 18152kb
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:
0 100000000000000000 0 0 100000000000000000 0 1 2522027 438209666288 0 100000000000000000 0 1 249512452 24966236662852 0 100000000000000000 0 0 100000000000000000 0 1 0 1000000000 0 0 1 0 0 2 0 0 1 1 0 1
result:
wrong answer 1st lines differ - expected: '5927443549 11285847934', found: '0'