# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
962048 |
2024-04-13T05:44:29 Z |
Amr |
Bridges (APIO19_bridges) |
C++17 |
|
48 ms |
3164 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=1000+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
ll res = 1;
x = x; // % mod;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1) res = (res*x) ; // % mod;
y = y>>1;
x = (x*x) ; // % mod;
}
return res;
}
vector<ll> e[N];
ll adj[N][N];
vector<pair<ll,ll> > v[N];
ll vis[N];
ll n , m , q;
void dfs(ll x, ll w)
{
if(vis[x]) return;
vis[x] = 1;
for(int i = 0; i < v[x].sz; i++)
{
ll to = v[x][i].F , curw = v[x][i].S;
if(curw>=w) dfs(to,w);
}
}
void solve()
{
cin >> n >> m;
for(int i = 0; i < m; i++)
{
ll x, y, w; cin >> x >> y >> w;
e[i] = {x,y,w};
v[x].push_back({y,w});
v[y].push_back({x,w});
}
cin >> q;
while(q--)
{
ll tp; cin >> tp;
if(tp==1)
{
ll j , w; cin >> j >> w; j--;
ll x = e[j][0] , y = e[j][1], curw = e[j][2];
e[j][2] = w;
ll lst = -1;
for(int i = 1; i < v[x].sz; i++)
{
if(v[x][i-1].F==y&&curw==v[x][i-1].S&&lst==-1) lst = i-1;
if(lst!=-1) swap(v[x][i],v[x][i-1]);
}
lst = -1;
for(int i = 1; i < v[y].sz; i++)
{
if(v[y][i-1].F==x&&curw==v[y][i-1].S&&lst==-1) lst = i-1;
if(lst!=-1) swap(v[y][i],v[y][i-1]);
}
v[x].back().S = w;
v[y].back().S = w;
}
else
{
ll s, w; cin >> s >> w;
//for(int i = 1; i <= n; i++) {for(int j = 0; j < v[i].sz; j++) cout << v[i][j].F << v[i][j].S << " "; cout << endl;}
for(int i = 1; i <= n; i++) vis[i] = 0;
dfs(s,w);
ll cnt = 0;
for(int i = 1; i <= n ;i++) if(vis[i]) cnt++;
cout << cnt << endl;
}
}
}
int main(){
//freopen("friday.in","r",stdin);
//freopen("friday.out","w",stdout);
fast;
while(TT--)
solve();
return 0;
}
Compilation message
bridges.cpp: In function 'void dfs(ll, ll)':
bridges.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < v[x].sz; i++)
| ^
bridges.cpp: In function 'void solve()':
bridges.cpp:67:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i = 1; i < v[x].sz; i++)
| ^
bridges.cpp:73:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 1; i < v[y].sz; i++)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
48 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
680 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
8 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
604 KB |
Output is correct |
9 |
Correct |
7 ms |
604 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
604 KB |
Output is correct |
14 |
Correct |
5 ms |
652 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
956 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
3164 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
956 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
48 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
680 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
8 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
604 KB |
Output is correct |
9 |
Correct |
7 ms |
604 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
604 KB |
Output is correct |
14 |
Correct |
5 ms |
652 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
608 KB |
Output is correct |
18 |
Runtime error |
2 ms |
956 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |