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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" #include "assert.h"
using namespace std; #define MAXN 200006
#define rep( i , a , b ) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per( i , a , b ) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all( x ) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; #define P 998244353 int n , m , q; vector<pair<int,ll> > G[MAXN];
priority_queue<pair<ll,int> > Q; ll dis[MAXN]; int vis[MAXN];
void dijk( ) { Q.push( mp( 0 , 1 ) ); memset( dis , 0x3f3f , sizeof dis ); dis[1] = 0; while( !Q.empty( ) ) { int u = Q.top( ).se; Q.pop( ); if( vis[u] ) continue; vis[u] = 1; for( auto &t : G[u] ) { int v = t.fi; if( dis[v] > dis[u] + t.se ) dis[v] = dis[u] + t.se , Q.push( mp( -dis[v] , v ) ); } } }
pii ed[MAXN];
ll d[MAXN]; vector<int> que[1000006];
void dij( ) { que[0].pb( 1 ); memset( d , 0x3f3f , sizeof d ); mem( vis ); d[1] = 0; for( int cur = 0 ; cur <= 1000000 ; ++cur ) { while( !que[cur].empty( ) ) { int u = que[cur].back( ); que[cur].pop_back( ); if( vis[u] ) continue; vis[u] = 1; for( auto &t : G[u] ) { int v = t.fi; if( d[v] > d[u] + t.se ) { d[v] = d[u] + t.se; if( d[v] <= 1000000 ) que[d[v]].pb( v ); } } } } }
void solve( ) { cin >> n >> m >> q; rep( i , 1 , m ) { static int u , v , w; scanf( "%d%d%d" , &u , &v , &w ); ed[i] = mp( u , G[u].size( ) ); G[u].eb( mp( v , w ) ); } dijk( ); rep( i , 1 , n ) for( auto &t : G[i] ) t.se += dis[i] - dis[t.fi]; int opt , c , e; rep( i , 1 , q ) { scanf( "%d" , &opt ); if( opt == 1 ) { dij( ); scanf( "%d" , &c ); printf( "%lld\n" , d[c] + dis[c] > 1e18 ? -1 : d[c] + dis[c] ); } else { scanf( "%d" , &c ); rep( j , 1 , c ) { scanf( "%d" , &e ); ++G[ed[e].fi][ed[e].se].se; } } } }
signed main( ) {
solve( ); }
|