이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 3e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m,q;
ll c[N];
bool vs[N];
vector<pll>adj[N];
struct cmp{
bool operator()(const pll &a, const pll &b){
return a.S > b.S;
}
};
void sub1(){
for(int i = 1; i <= m;i++){
ll u,v,w; cin >> u >> v >> w;
adj[u].pb({v, i}), adj[v].pb({u, i});
c[i] = w;
}
cin >> q;
while(q--){
ll typ; cin >> typ;
if(typ == 1){
ll x,y; cin >> x >> y;
c[x] = y;
}
else{
ll s,w; cin >> s >> w;
for(int i = 1; i <= n;i++) vs[i] = 0;
vs[s] = 1;
queue<ll>q;
q.push(s);
while(q.size()){
ll u = q.front();q.pop();
for(auto v : adj[u]){
if(vs[v.F] || w > c[v.S]) continue;
vs[v.F] = 1;
q.push(v.F);
}
}
ll res = 0;
for(int i = 1; i <= n;i++) if(vs[i]) res++;
cout << res << "\n";
}
}
}
void to_thic_cau(){
cin >> n >> m;
if(max(n, m) <= 1000) sub1();
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |