-
Notifications
You must be signed in to change notification settings - Fork 3
/
D.cpp
77 lines (76 loc) · 1.95 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
using namespace std;
using ll=long long;
using pil=pair<int,ll>;
const int N=1E5+10;
const ll inf=1E18;
template<typename T=int>T read(){T x;cin>>x;return x;}
template<typename U,typename V>bool cmin(U &x,V y){return x>y?x=y,true:false;}
template<typename U,typename V>bool cmax(U &x,V y){return x<y?x=y,true:false;}
int head[N],nex[N],to[N],w[N],n,m,s;
ll dis[N];
namespace dij1
{
struct cmp{bool operator()(pil &x,pil &y){return x.se>y.se;}};
priority_queue<pil,vector<pil>,cmp>q;
void ins(int x,ll d){if(cmin(dis[x],d))q.emplace(x,d);}
void work()
{
for(int i=1;i<=n;++i)dis[i]=inf;
ins(1,0);
while(!q.empty())
{
auto [x,d]=q.top();
q.pop();
if(d^dis[x])continue;
for(int i=head[x];i;i=nex[i])ins(to[i],d+w[i]);
}
for(int i=1;i<=n;++i)if(dis[i]==inf)dis[i]=-1;
}
}
namespace dij2
{
int h[N];
vector<int>q[N];
void ins(int x,int t){if(cmin(h[x],t))q[t].eb(x);}
void work(int c)
{
for(int i=1;i<=n;++i)h[i]=c+1;
ins(1,0);
for(int i=0;i<=c;++i)while(!q[i].empty())
{
int x=q[i].back();
q[i].pop_back();
if(i^h[x])continue;
for(int j=head[x];j;j=nex[j])ins(to[j],dis[x]+i+w[j]-dis[to[j]]);
}
for(int i=1;i<=n;++i)if(~dis[i])dis[i]+=h[i];
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m>>s;
for(int i=1,u,v;i<=m;++i)
{
cin>>u>>v>>w[i];
nex[i]=head[u];
head[u]=i;
to[i]=v;
}
dij1::work();
while(s--)
{
if(read()&1)cout<<dis[read()]<<'\n';
else
{
int c=read();
for(int i=c;i--;++w[read()]);
dij2::work(min(c,n-1));
}
}
return 0;
}