This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <fstream>
#include <iomanip>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using pb = pair<bool, bool>;
using vpb = vector<pb>;
using vvpb = vector<vpb>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e18;
#define FAST ios_base::sync_with_stdio(0)
#define FASTIN cin.tie(0)
#define FASTOUT cout.tie(0)
#define upmin(a, b) a = min(a, b)
#define upmax(a, b) a = max(a, b)
#define pr(x) cout << x << endl;
#define prv(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define prvv(v) for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl;
#define wpr(x) cout << #x << " = " << (x) << endl;
#define wprv(v) cout << #v << ": " << endl; for(auto it : v) cout << *it << " "; cout << endl;
#define wprvv(v) cout << #v << ": " << endl; for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl;
#define rep(i,s,e) for(ll i = s; i < e; i++)
#define all(x) x.begin(),x.end()
#define pb push_back
ll n, m, q;
vvpll graph;
vpll nodes;
vpll inds;
void dfs(ll cur, vb &vis, ll w)
{
vis[cur] = true;
for (auto& nei : graph[cur]) {
if (vis[nei.first]) continue;
if (nei.second < w) continue;
dfs(nei.first, vis, w);
}
}
void solve()
{
cin >> n >> m;
graph.resize(n);
rep(i, 0, m) {
ll xt, yt, dt;
cin >> xt >> yt >> dt;
xt--, yt--;
graph[xt].push_back({ yt, dt });
graph[yt].push_back({ xt, dt });
nodes.push_back({ xt, yt });
inds.push_back({graph[xt].size() - 1, graph[yt].size() - 1});
}
cin >> q;
while (q--) {
ll type;
cin >> type;
if (type == 1) {
ll i, v;
cin >> i >> v;
i--;
graph[nodes[i].first][inds[i].first].second = v;
graph[nodes[i].second][inds[i].second].second = v;
}
else {
ll w, s;
cin >> s >> w;
s--;
vb vis(n, 0);
dfs(s, vis, w);
ll ans = 0;
rep(i, 0, n) {
if (vis[i]) ans++;
}
pr(ans);
}
}
}
int main()
{
FAST;
FASTIN; FASTOUT;
solve();
}
/*
5 4
1 2 1
2 3 2
3 4 3
4 5 4
100
2 3 2
*/
# | 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... |