Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define NguyenDangQuan the_author
- #define task ""
- #define all(x) x.begin(),x.end()
- #define fi first
- #define se second
- #define pb push_back
- #define ld long double
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- int typetest;
- inline void fastIOfileinput(){
- ios_base:: sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if(fopen(task".inp", "r")){
- freopen(task".inp", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- if(fopen(task".in", "r")){
- freopen(task".in", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- typetest = 0;
- }
- struct dat{
- int id;
- ll w;
- dat() {}
- dat(int u, ll v){
- this->id = u;
- this->w = v;
- }
- bool operator <(const dat& a) const{
- return w > a.w
- ||(w == a.w && id > a.id);
- }
- };
- int n, m, t;
- vector <dat> ke[501];
- bool on[501];
- inline void Enter(){
- memset(on, 0, sizeof(on));
- cin >> n >> m >> t;
- for(int i = 1; i <= m; ++i){
- int a, b;
- ll c;
- cin >> a >> b >> c;
- ke[a].pb(dat(b, c));
- }
- }
- ll BFS(int x, int y){
- bool free[n + 1];
- memset(free, 1, sizeof(free));
- priority_queue<dat, vector<dat> > open;
- open.push(dat(x, 0));
- while( !open.empty() ) {
- auto c = open.top();
- open.pop();
- free[c.id] = 1;
- if(c.id == y) return c.w;
- for(auto i : ke[c.id]){
- if(free[i.id] || (!on[i.id] && i.id != y) ) continue;
- open.push(dat(i.id, i.w + c.w));
- }
- }
- return -1;
- }
- inline void solve(){
- int typ;
- while(t--){
- cin >> typ;
- if(typ == 1){
- cin >> typ;
- on[typ] = 1;
- continue;
- }
- int x, y;
- cin >> x >> y;
- ll ans = BFS(x, y);
- cout << ans << "\n";
- }
- }
- int main(){
- fastIOfileinput();
- if(typetest){
- int t;
- cin >> t;
- while(t--){
- Enter();
- solve();
- }
- }
- else{
- Enter();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement