QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617547 | #9434. Italian Cuisine | zzpcd# | RE | 0ms | 0kb | C++20 | 3.8kb | 2024-10-06 16:07:23 | 2024-10-06 16:07:24 |
answer
#include<bits/stdc++.h>
#define P make_pair
#define N 500010
using namespace std;
int n,vis[N],m,K;
struct edge
{
int v,pre,c,l;
}e[N<<1];
int fir[N],tot=1;
void adde(int u,int v,int c,int l)
{
e[++tot]={v,fir[u],c,l};fir[u]=tot;
e[++tot]={u,fir[v],c,l};fir[v]=tot;
return ;
}
struct node
{
int now;
long long dis;
int id;
friend bool operator <(const node &i,const node &j)
{
if(i.now==j.now)
{
return i.dis>j.dis;
}
else
{
return i.now>j.now;
}
}
}dat[N];
priority_queue<node> q;
struct opt
{
int a,b;
}op[N];
vector<pair<int,int>> vec[N];
vector<pair<int,int>> bz[N][20];
int getpos(int c,int ll,int val)
{
int l=0,r=vec[c].size()-1;
while(l<r)
{
int mid=l+r>>1;
if(vec[c][mid].first>ll) r=mid;
else l=mid+1;
}
if(r>=vec[c].size()||vec[c][r].first<=ll) return K+1;
int now=l;
for(int j=19;j>=0;--j)
{
if(bz[c][j][now].second<val)
{
now=bz[c][j][now].first;
}
}
++now;
if(now>=vec[c].size()||bz[c][0][now].second<val) return K+1;
return now;
}
void dij()
{
while(!q.empty()) q.pop();
q.push({1,0ll,1});
fill(vis,vis+n+5,0);
while(!q.empty())
{
auto [now,dis,u] = q.top();
q.pop();
cerr << u <<" ::: " << now <<" " << dis <<"??\n";
if(vis[u]) continue;
vis[u]=true;
for(int i=fir[u];i;i=e[i].pre)
{
int v=e[i].v;
if(e[i].c==op[now].a)
{
if(dis+e[i].l<=op[now].b)
{
node tmp={now,dis+e[i].l,v};
if(dat[v]<tmp)
{
dat[v]=tmp;
q.push(dat[v]);
}
}
else
{
int p=getpos(e[i].c,now,e[i].l);
if(p==K+1) continue;
node tmp={p,e[i].l,v};
if(dat[v]<tmp)
{
dat[v]=tmp;
q.push(dat[v]);
}
}
}
else
{
int p=getpos(e[i].c,now,e[i].l);
if(p==K+1) continue;
node tmp={p,e[i].l,v};
if(dat[v]<tmp)
{
dat[v]=tmp;
q.push(dat[v]);
}
}
}
}
return ;
}
void _()
{
cin>>n>>m>>K;
tot=1;
for(int i=1;i<=n;++i) fir[i]=0,dat[i]={(int)2e9,(long long)2e18,i};
for(int i=1;i<=m;++i)
{
int u,v,c,l;
cin>>u>>v>>c>>l;
adde(u,v,c,l);
vec[i].clear();
}
for(int i=1;i<=K;++i)
{
cin>>op[i].a>>op[i].b;
vec[op[i].a].push_back({i,op[i].b});
}
for(int i=1;i<=m;++i)
{
for(int j=0;j<20;++j)
{
for(int t=0;t<vec[i].size();++t) bz[i][j].push_back(P(0,0));
for(int p=0;p<vec[i].size();++p)
{
if(j==0)
{
bz[i][j][p]=P(p+1,vec[i][p].second);
}
else
{
bz[i][j][p]=P(bz[i][j-1][bz[i][j-1][p].first].first,max(bz[i][j-1][p].second,bz[i][j-1][bz[i][j-1][p].first].second));
}
}
}
}
// cerr << "???\n";
dij();
for(int i=1;i<=n;++i) cout<<vis[i];
cout<<'\n';
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin>>T;
while(T--) _();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 1 1 1 0 0 1 0 5 0 3 3 0 5 6 2 4 1 2 0 4 0 6 3 4 6 2 6 0 3 4 3 3 1 3 0 6 3 3 6 0 3
output:
10000