QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865431 | #8673. 最短路径 | ucup-team052 | 0 | 55ms | 30732kb | C++23 | 2.7kb | 2025-01-21 18:33:47 | 2025-01-21 18:33:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 200005
vector<pair<int,int>> G[2][N];
int n,m,Q;
void generate_edges(int n, int m) {
unsigned seed; cin>>seed;
std::mt19937 gen(seed);
unsigned max = -1u / n * n;
auto sample = [&]() {
unsigned x;
do { x = gen(); } while(x >= max);
return x % n + 1;
};
for(int i=1;i<=m;i++) {
int u,v,w;
u = sample();
v = sample();
w = gen();
// printf("%lld %lld %lld\n",u,v,w);
G[0][u].emplace_back(v,w);
G[1][v].emplace_back(u,w);
} // u 到 v 存在边权为 w 的边=
}
struct Node
{
int u,w,uu,id;
Node(int a=0,int b=0,int c=-1,int d=-1)
{
u=a,w=b,uu=c,id=d;
}
bool operator < (const Node &x) const
{
return w>x.w;
}
};
int dis[2][N],lst[2][N];
priority_queue<Node> q[2];
vector<int> nd[2];
signed main()
{
cin>>n>>m>>Q;
generate_edges(n, m);
for(int t=0;t<2;t++) for(int i=1;i<=n;i++)
{
sort(G[t][i].begin(),G[t][i].end(),[&](auto u,auto v){
return u.second<v.second;
});
}
for(int t=1;t<=Q;t++)
{
int u=read(),v=read();
// q[0].clear(),q[1].clear();
while(!q[0].empty()) q[0].pop();
while(!q[1].empty()) q[1].pop();
dis[0][u]=0,dis[1][v]=0;
lst[0][u]=t,lst[1][v]=t;
q[0].emplace(u,0);
q[1].emplace(v,0);
int ok=0;
for(int op=0;ok==0;op^=1)
{
if(q[op].empty())
{
ok=1;
break;
}
auto [u,w,uu,id]=q[op].top(); q[op].pop();
if(dis[op][u]!=w) {op^=1; continue;}
// printf("%d : %d %d %d %d\n",op,u,w,uu,id);
auto push=[&](int uu,int id){
while(id+1!=(int)G[op][uu].size())
{
id++;
auto [v,e]=G[op][uu][id];
if(lst[op][v]!=t||dis[op][v]>w+e)
{
if(lst[op][v]!=t) nd[op].push_back(v);
lst[op][v]=t,dis[op][v]=w+e;
if(lst[op^1][v]==t) ok=2;
q[op].emplace(v,w+e,uu,id);
break;
}
}
};
if(uu!=-1) push(uu,id);
push(u,-1);
}
if(ok==1) printf("-1\n");
else
{
int ans=INF;
for(int u:nd[0])
{
for(auto [v,w]:G[0][u])
{
if(lst[1][v]==t) ans=min(ans,dis[0][u]+w+dis[1][v]);
}
}
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: 5
Accepted
time: 0ms
memory: 10068kb
input:
4 8 5 1112792816 2 3 4 3 4 3 3 2 1 4
output:
3419197189 1798364963 1798364963 3986398077 2337967903
result:
ok 5 lines
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 10224kb
input:
2000 2000 2000 3336994405 659 1650 1678 341 818 235 1380 1865 1927 1366 1233 1673 267 1698 775 1022 1255 1110 1533 1928 1854 169 1579 729 449 1335 943 583 360 50 795 926 1584 911 1924 604 280 309 1429 420 1107 1858 1466 76 265 1109 1077 622 245 1941 957 1434 1560 1128 122 51 229 925 826 1006 851 323...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 157th lines differ - expected: '787133140', found: '7485649103'
Subtask #2:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
input:
3000 3000000 10000 37461678 2873 1368 1757 2000 1262 1822 2484 1778 2055 2096 2545 366 2923 2028 1469 1874 691 631 1173 2967 894 2020 1207 881 373 236 1913 1923 1351 16 1066 2032 471 1561 1047 2043 457 145 2728 1752 2521 1199 1568 904 2515 543 1472 2161 748 2744 748 1908 912 172 2340 2494 977 267 10...
output:
46325123 37479074 45953591 34294672 48869513 49285454 39467842 45975844 40840906 29515903 8878143 18807744 51519763 28825501 25983590 36512035 7499773 24708686 6808987 17152127 26896787 35720399 34988203 44754658 22793103 23882533 36848784 18307953 32979152 24414242 30393640 27849810 30110296 259381...
result:
Subtask #3:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 55ms
memory: 30732kb
input:
200000 200000 10000 1824322211 104482 112162 130667 13436 36792 142259 51832 97549 15358 180076 128251 92635 45296 195115 62109 38014 22014 86754 79735 103777 94797 96086 196760 5955 45622 59618 12995 62585 55686 156402 23085 68138 170749 148553 97603 160274 112975 22651 116322 190720 84774 57075 23...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 679th lines differ - expected: '172751101166', found: '147633166028'
Subtask #4:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
200000 500000 10000 3113327438 68816 31422 174349 125983 18111 188786 84806 87249 142007 180723 95611 116398 104758 196349 77547 89859 120350 77199 110906 10209 177461 194861 115505 105566 27493 166237 15676 158290 86204 116010 159979 125659 132461 61989 194289 157721 18830 82910 166696 98162 125208...
output:
30750221387 -1 29251470861 26738736374 -1 32231718172 -1 -1 34992516865 25882119211 -1 -1 24323353360 16002670927 19252049057 -1 -1 -1 20802221296 18180806782 25314276023 25154865454 -1 13868174837 20868761290 22654898600 -1 30258390952 14460952812 -1 20016379937 18253257637 -1 26302128024 210147898...
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
200000 500000 10000 1843053063 3409 108359 168924 184622 13119 119837 109492 38050 97152 51201 49047 12472 183998 191613 193074 177289 194248 104409 15509 88499 61967 143398 4532 56790 196650 158711 63655 70744 140178 107299 63530 87330 127334 159237 7134 184418 125289 28604 176966 179527 181695 128...
output:
30052433699 31322976984 32837183027 32410329464 -1 26156919275 28525153254 16803572646 31877761170 21809398810 22792400146 17660341603 30569297246 17761021169 25461913509 18266748235 11890791562 -1 -1 21408306065 21053483022 25330033342 22941826166 21811750726 25968936470 16728245748 21531281903 197...
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #24:
score: 0
Time Limit Exceeded
input:
100000 3000000 10000 3892765041 14843 34156 43390 49542 38564 95501 26194 87126 18638 53346 69414 47011 95472 58303 44370 77172 75652 90555 94386 31888 47911 9905 70599 97061 52764 24896 31445 15589 82314 43852 97155 93412 11834 45082 75614 42459 67802 32024 82389 4968 32860 62514 97630 28012 14839 ...
output:
2757100922 1768979329 1331407892 2220949229 2232480433 1930900644 2078042498 2027466874 1845889798 2089325829 1503413718 1475795131 2146792728 1445169091 1880558235 1257651636 1399937171 2424823489 2050892755 1280907832 1394941461 1648384863 2344983793 1192936374 775509707 1632821150 1215288828 1391...
result:
Subtask #7:
score: 0
Time Limit Exceeded
Test #33:
score: 0
Time Limit Exceeded
input:
200000 3000000 10000 3910662331 161257 40967 50546 86049 199665 199302 177403 36274 158790 143151 193304 78511 28032 149723 96394 37099 2157 76024 195400 34830 41933 147591 191613 96468 194837 67293 57992 63117 24749 6694 117818 87323 46130 53470 174812 24950 149173 124886 119910 54123 2297 124533 5...
output:
4610172890 4369337660 4540863563 4978448106 4879322831 3832155195 3775123334 4346348440 3643289296 3431522951 2370706494 3957403011 2892203709 3403630548 3343667163 3762693708 3727788836 3623290784 2856569248 3743376491 3715184824 3140510913 3985172713 2949779468 3276972716 3272291776 3486303380 273...