QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94482 | #4357. School Road | tricyzhkx | 0 | 205ms | 34480kb | C++14 | 2.3kb | 2023-04-06 13:20:50 | 2023-04-06 13:20:52 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
int n,cnt,dfn[100010],low[100010],ffa[100010],tot;
ll dis1[100010],dis2[100010];
bool vis[100010],good[100010];
stack<int> stk;
queue<int> que;
vector<pair<int,int>> G[100010];
map<int,bool> g[100010];
struct node
{
int v;ll w;
node(int _v=0,ll _w=0):v(_v),w(_w){}
bool operator<(const node &a)const{return w>a.w;}
};
void Dij(int s,ll *dis)
{
priority_queue<node> que;
fill(dis+1,dis+n+1,INF);
memset(vis+1,0,sizeof(bool)*n);
dis[s]=0;que.emplace(s,0);
while(!que.empty())
{
node t=que.top();que.pop();
if(vis[t.v]) continue;
int u=t.v;vis[u]=1;
for(auto p:G[u])
{
int v=p.first,w=p.second;
if(dis[v]>dis[u]+w) dis[v]=dis[u]+w,que.emplace(v,dis[v]);
}
}
}
void tarjan(int u,int fa)
{
dfn[u]=low[u]=++tot;
stk.push(u);
for(auto p:G[u])
{
int v=p.first;
if(!dfn[v])
{
tarjan(v,u);low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
int w;cnt++;
do
{
w=stk.top();stk.pop();
ffa[w]=cnt;
}while(w!=v);
ffa[cnt]=u;
}
}
else if(v!=fa) low[u]=min(low[u],dfn[v]);
}
}
void add(int u,int v){g[u][v]=g[v][u]=1;}
void push(int u){if(u!=1 && u!=n && g[u].size()<=2) que.push(u);}
int main()
{
int m,u,v,w;
cin>>n>>m;cnt=n;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
G[u].emplace_back(v,w);G[v].emplace_back(u,w);
}
Dij(1,dis1);Dij(n,dis2);
G[1].emplace_back(n,-1);
G[n].emplace_back(1,-1);
tarjan(1,0);good[1]=1;
for(int i=2;i<=n;i++)
if(ffa[i]==ffa[n]) good[i]=1;
for(int u=1;u<=n;u++)if(good[u])
for(auto p:G[u])
{
int v=p.first,w=p.second;
if(!good[v] || w<0 || dis1[v]+w+dis2[u]==dis1[n]) continue;
if(dis1[u]+w+dis2[v]!=dis1[n]) return assert(false),puts("1"),0;
}
for(int u=1;u<=n;u++)if(good[u])
for(auto p:G[u])
{
int v=p.first,w=p.second;
if(w>=0 && good[v] && dis1[u]+w+dis2[v]==dis1[n]) add(u,v);
}
for(int i=2;i<n;i++) push(i);
while(!que.empty())
{
int u=que.front();que.pop();
if(!g[u].size()) continue;
assert(g[u].size()==2);
vector<int> vec;
for(auto p:g[u]) g[p.first].erase(u),vec.push_back(p.first);
add(vec[0],vec[1]);
push(vec[0]);push(vec[1]);
g[u].clear();
}
return puts(g[1].size()==1 && g[1][n]?"0":"1"),0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 7
Accepted
time: 1ms
memory: 10628kb
input:
14 40 8 12 570429827 6 10 592780730 13 14 299807355 4 10 729771483 4 10 729771483 6 9 746405411 2 3 696576351 12 14 192640790 4 13 284900209 1 2 857968292 12 14 192640790 8 12 570429827 6 10 592780730 6 9 746405411 9 11 329648726 4 13 284900209 2 3 696576351 4 10 729771483 5 11 101819611 3 7 1824073...
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 2ms
memory: 10688kb
input:
41 40 12 19 102666211 30 32 10931929 8 34 88862177 11 29 37284876 6 35 24117284 6 11 24483138 10 35 11019124 4 22 509961847 20 39 77098829 25 33 563195350 22 24 781289886 2 17 238185039 21 27 288940653 3 31 62767763 18 21 350694322 2 40 228181439 3 33 109276182 31 36 203571934 28 34 64098677 14 24 3...
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 10608kb
input:
41 40 2 21 69489336 7 32 715357509 25 38 324791430 1 39 430674626 15 40 551039547 5 18 334574228 23 37 712919654 9 27 367576234 15 38 171641096 5 36 183325856 1 6 339460052 23 26 796129406 31 35 572322695 34 35 783409641 2 4 754027046 8 33 413068373 29 33 900915508 10 13 296104622 32 39 88880510 17 ...
output:
0
result:
ok single line: '0'
Test #4:
score: -7
Dangerous Syscalls
input:
40 40 7 39 44916253 4 18 958910119 9 37 670785398 3 8 753908936 34 39 917194277 25 31 554847014 6 36 606005704 3 20 104555289 29 31 898892301 4 10 641381082 24 30 321262615 15 24 978365334 13 19 237154728 1 30 159127129 1 38 273921427 33 35 95259264 35 40 9238012 9 25 518899851 12 22 920531620 32 38...
output:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #11:
score: 15
Accepted
time: 7ms
memory: 10676kb
input:
18 40 3 10 26965732 5 15 67047331 3 17 42474964 13 15 129212204 9 18 142540287 2 14 27157962 5 15 67047331 5 15 67047331 5 15 67047331 4 16 212978971 6 12 51548223 4 18 192438222 13 16 60052417 16 17 162364835 6 17 55527270 9 11 58810843 3 7 95393586 13 15 129212204 2 17 67824762 5 15 67047331 15 16...
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 3ms
memory: 10744kb
input:
18 51 5 16 489370441 7 8 674383722 8 11 602435525 1 10 856666364 13 18 650829027 11 14 198398173 3 4 613940394 15 17 123758204 8 11 602435525 3 6 567757815 13 18 650829027 14 15 236674174 3 4 613940394 5 18 956980171 6 16 887883755 3 6 567757815 6 16 887883755 5 18 956980171 4 10 339471731 11 14 198...
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 48ms
memory: 14232kb
input:
18 200000 8 17 279042056 12 13 907447344 2 16 240997679 3 7 820773384 1 5 45712022 2 16 240997679 4 18 239293113 9 14 389857788 4 18 239293113 4 18 239293113 1 11 409366186 3 12 208134361 2 16 240997679 13 17 263089947 1 5 45712022 4 18 239293113 4 7 528521172 2 9 629050323 8 17 279042056 12 13 9074...
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 33ms
memory: 13912kb
input:
18 200000 12 14 787958557 3 17 309856381 7 16 602540874 6 12 343810291 12 14 561222017 7 16 125534085 9 17 870511470 7 16 118408057 10 15 452922275 6 12 983055551 3 17 599421596 9 17 344601220 10 15 627856971 6 12 821612223 9 13 652746776 2 3 86605360 14 16 845498029 4 5 531236117 6 12 308924509 5 1...
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 29ms
memory: 13668kb
input:
18 199999 6 16 312811855 5 10 658600889 8 13 23117786 2 11 838354308 2 16 681349134 9 17 650741046 3 12 902316677 8 13 557626383 7 13 747622028 14 15 246861375 5 10 779694159 11 15 507769124 7 13 310445554 7 13 668124445 5 10 558567743 3 17 535103743 5 10 122705300 4 6 559392043 14 15 427912040 8 13...
output:
0
result:
ok single line: '0'
Test #16:
score: -15
Dangerous Syscalls
input:
18 200000 8 16 273673687 9 11 360275441 4 6 922867054 4 14 84928274 6 13 968233426 2 12 812572590 11 15 71503040 4 6 980374167 9 11 223188493 8 16 115328427 10 13 361608292 6 13 37132062 10 13 545962114 9 11 390680169 3 14 698353284 7 10 584994105 8 16 55684470 8 16 284428277 6 13 124379775 2 5 2317...
output:
result:
Subtask #3:
score: 0
Dangerous Syscalls
Test #18:
score: 23
Accepted
time: 156ms
memory: 34368kb
input:
100000 99999 42115 93495 19881095 21969 68351 161710 7405 86343 27129 37307 45676 320013 30388 71545 117761 22026 68957 65332 77949 81644 2281387 24865 95079 341488 9849 98496 2548159 53911 79572 4962105 24880 62622 1678564 15943 22168 1524688 67424 78323 2450655 32175 74893 1908332 35640 39305 1043...
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 205ms
memory: 34480kb
input:
100000 100013 19959 56142 776045 6894 37840 718015 11415 73383 1519031 35732 78712 566052 78739 96739 584053 24958 28098 854234 27498 62413 1735265 27341 91341 11692771 46008 96501 299421 14384 78871 1903953 15562 33609 158393 5270 76189 69630274 38130 51331 187183 61589 75145 81438587 45138 86388 5...
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 106ms
memory: 23336kb
input:
100000 100013 30467 74396 2840367 12869 90814 1569862 18883 60521 211271 95973 98805 3444504 52606 61422 697591 49637 61784 1034159 21957 33982 3827036 10128 68617 444124 20731 81447 5807317 15570 35763 123607 22128 33827 59368 34479 41370 15053204 52297 55748 435155 22820 56102 66369 19316 92816 76...
output:
0
result:
ok single line: '0'
Test #21:
score: -23
Dangerous Syscalls
input:
100000 100013 6205 55122 513428 28020 94742 60755466 48078 86373 1325655 61744 68231 26052939 37580 98090 9672421 212 97377 3362861 54617 85198 820827 18698 55299 25810204 67840 93714 1138074 30462 46234 1718665 5128 72146 9162 58950 61074 307192 51972 95908 17177745 21488 31396 49979 62397 85443 36...
output:
result:
Subtask #4:
score: 0
Dangerous Syscalls
Test #57:
score: 35
Accepted
time: 2ms
memory: 10696kb
input:
18 400 11 18 145314505 1 18 242896789 1 18 242896789 5 13 31030812 13 18 93451080 1 18 242896789 1 7 123378068 1 18 242896789 1 18 242896789 1 18 242896789 1 18 242896789 1 18 242896789 1 18 242896789 1 3 42183985 1 18 242896789 13 18 93451080 1 18 242896789 13 18 93451080 1 18 242896789 1 18 242896...
output:
0
result:
ok single line: '0'
Test #58:
score: 0
Accepted
time: 56ms
memory: 13732kb
input:
18 200000 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 758096510 1 18 ...
output:
0
result:
ok single line: '0'
Test #59:
score: -35
Dangerous Syscalls
input:
18 200000 1 16 142470606 1 16 142470606 1 16 142470606 1 16 142470606 1 18 403405575 1 18 403405575 1 18 403405575 1 18 403405575 1 18 403405575 1 16 142470606 1 16 142470606 1 18 403405575 1 18 403405575 1 18 403405575 1 18 403405575 1 18 403405575 1 16 142470606 1 18 403405575 1 16 142470606 16 18...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%