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 <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define MAXN 100013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N, M, Q;
pair<pii, int> edge[MAXN];
vi edges[MAXN];
pair<pii, int> quer[MAXN];
bitset<MAXN> vis;
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
cin >> N >> M;
FOR(i, 0, M)
{
int u, v, d;
cin >> u >> v >> d;
u--; v--;
edge[i] = {{u, v}, d};
edges[u].PB(i);
edges[v].PB(i);
}
cin >> Q;
FOR(i, 0, Q)
{
cin >> quer[i].se >> quer[i].fi.fi >> quer[i].fi.se;
quer[i].fi.fi--;
}
FOR(i, 0, Q)
{
int idx = quer[i].fi.fi, val = quer[i].fi.se;
if (quer[i].se == 1)
{
edge[idx].se = val;
}
else
{
vis.reset();
vis[idx] = true;
vi q; q.PB(idx);
while(!q.empty())
{
int u = q.back(); q.pop_back();
for (int eid : edges[u])
{
int v = edge[eid].fi.fi ^ edge[eid].fi.se ^ u;
if (edge[eid].se >= val && !vis[v])
{
vis[v] = true;
q.PB(v);
}
}
}
cout << vis.count() << '\n';
}
}
return 0;
}
# | 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... |