题解:CF827F Dirty Arkady's Kitchen
CF827F Dirty Arkady's Kitchen
由于有开放时间和不能停留的限制,此时从最快到达时间转移就没有正确性了,因为可能到了这里走不了。不过注意到,由于是无向图,到了
考虑此时出现时间的限制,先将所有边按照
:::info[代码]
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define psb push_back
#define SZ(vec) ((int)vec.size())
#include <queue>
using namespace std;
const int N=500010;
int n,m;
struct Node
{
int u,v,l,r,dir;
bool operator < (const Node &o) const { return l>o.l; }
};
priority_queue<Node> q;
int f[N][2];
vector<Node> buc[N][2];
void spread(int u,int v,int l,int r)
{
bool op=(l&1);
if (f[u][op]>=l)
{
if (v==n)
{
cout << l+1 << "\n";
exit(0);
}
if (f[v][!op]<=r+1)
{
f[v][!op]=r+1;
for (Node t : buc[v][!op]) q.push({t.u,t.v,l+1,t.r,1});
buc[v][!op].clear();
}
}
else buc[u][op].psb({u,v,l,r});
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> m;
if (n==1)
{
puts("0");
return 0;
}
for (int i=1;i<=m;i++)
{
int u,v,l,r;
cin >> u >> v >> l >> r; r--;
bool op=((l&1)==(r&1));
q.push({u,v,l,r-(!op),0});
q.push({u,v,l+1,r-op,0});
}
memset(f,0xcf,sizeof(f));
f[1][0]=0;
while (q.size())
{
auto [u,v,l,r,dir]=q.top(); q.pop();
if (l>r) continue;
spread(u,v,l,r);
if (!dir) spread(v,u,l,r);
}
puts("-1");
return 0;
}
:::