제출 #568734

#제출 시각아이디문제언어결과실행 시간메모리
568734birthdaycake다리 (APIO19_bridges)C++17
0 / 100
3065 ms15540 KiB
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
 
 

vector<pair<int,int>>adj[200001];
int vs[200001];

signed main() {
 
    int n,m; cin >> n >> m;
    vector<pair<int,pair<int,int>>>edg(m);
    for(int i = 0; i < m; i++){
        int a,b,c; cin >> a >> b >> c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
        edg[i] = {a,{b,c}};
    }
    int q; cin >> q;
    while(q--){
        int t; cin >> t;
        if(t == 1){
            int x,y; cin >> x >> y;
            x--;
            int a = edg[x].first, b = edg[x].second.first, c = edg[x].second.second;
            for(auto s: adj[a]){
                if(s.first == b && s.second == c){
                    if(s != adj[a].back()) swap(s,adj[a].back());
                    adj[a].pop_back();
                    adj[a].push_back({b,y});
                    break;
                }
            }
            for(auto s: adj[b]){
                if(s.first == a && s.second == c){
                    if(s != adj[b].back()) swap(s,adj[b].back());
                    adj[b].pop_back();
                    adj[b].push_back({a,y});
                    break;
                }
            }
        }else{
            int s,w, ans = 1; cin >> s >> w;
            queue<int>d;
            for(int i = 1; i <= n; i++) vs[i] = 0;
            vs[s] = 1;
            d.push(s);
            while(d.size()){
                auto y = d.front();
                d.pop();
                for(auto s:adj[y]){
                    if(s.second >= w){
                        if(!vs[s.first]){
                            ans++;
                            vs[s.first] = 1;
                            d.push(s.first);
                        }
                    }
                }
            }
            cout << ans << endl;
        }
    }
 
    /*
     
     
     
     
     3 4
     1 2 5
     2 3 2
     3 1 4
     2 3 8
     */
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...