제출 #821929

#제출 시각아이디문제언어결과실행 시간메모리
821929smirichto다리 (APIO19_bridges)C++17
0 / 100
3 ms340 KiB
#include<bits/stdc++.h> using namespace std ; // dsu with rollback int n , q , m ; const int B = 150 , N = 1e5 + 5 ; stack<int> stck; int sz[N], cmp[N]; void reset() { iota(cmp + 1, cmp + 1 + n, 1); fill(sz + 1, sz + n + 1, 1); // while (!stck.empty()) stck.pop() ; } inline int find(int a) { while (cmp[a] != a) a = cmp[a]; return a; } void onion(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (sz[a] > sz[b]) swap(a, b); stck.push(a); sz[b] += sz[a]; cmp[a] = cmp[b]; } void rollback(int x) { assert(x>=0) ; while (stck.size() > x) { int k = stck.top(); stck.pop(); sz[cmp[k]] -= sz[k]; cmp[k] = k; } } vector<array<int,4>> qr[B]; int ans[N] , typ[N]; pair<int,int> endpoints[N] ; int old[N] , changed[N] ; void solve(){ cin>>n>>m ; for(int i = 1 ; i<=m ; i++){ int u , v , w ; cin>>u>>v>>w ; endpoints[i] = make_pair(u , v) ; old[i] = w ; } cin>>q ; for(int i = 1 ; i<=q ; i++){ int tp , a , b ; cin>>tp>>a>>b ; qr[i/B].push_back({tp , a , b , i}) ; typ[i] = tp ; } for(int block = 0 ; block<=q/B ; block++){ reset() ; vector<array<int,3>> vec , updates ; for(auto a : qr[block]){ if(a[0]==1){ changed[a[1]] = 1 ; updates.push_back({a[3] , a[1] , a[2]}) ; } else{ vec.push_back({a[2] , a[1] , a[3]}) ; } } vector<array<int,2>> edges ; for(int j = 1 ; j<=m ; j++){ if(changed[j]) continue; edges.push_back({old[j] , j}) ; } sort(edges.begin() , edges.end()) ; reverse(edges.begin() , edges.end()) ; int j = 0 ; sort(vec.begin() , vec.end()) ; reverse(vec.begin() , vec.end()) ; for(int i = 0 ; i<vec.size() ; i++){ while(j<edges.size() && edges[j][0]>=vec[i][0]){ onion(endpoints[edges[j][1]].first , endpoints[edges[j][1]].second) ; ++j ; } int c = stck.size() ; for(int k = 0 ; k<updates.size() ; k++){ int e = updates[k][1] ; int u = endpoints[e].first , v = endpoints[e].second ; int w = updates[k][2] ; if(updates[k][0]>vec[i][2]){ w = old[e] ; } if(w>=vec[i][0]){ onion(u , v) ; } } ans[vec[i][2]] = sz[find(vec[i][1])] ; rollback(c) ; } for(auto a : updates){ old[a[1]] = a[2] ; changed[a[1]] = 0 ; } } for(int i = 1 ; i<=q ; i++){ if(typ[i]==1) continue; cout<<ans[i]<<endl; } } int main(){ ios::sync_with_stdio(false) ; cin.tie(nullptr) ; #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif solve() ; }

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'void rollback(int)':
bridges.cpp:33:24: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     while (stck.size() > x) {
      |            ~~~~~~~~~~~~^~~
bridges.cpp: In function 'void solve()':
bridges.cpp:85:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int i = 0 ; i<vec.size() ; i++){
      |                         ~^~~~~~~~~~~
bridges.cpp:86:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |             while(j<edges.size() && edges[j][0]>=vec[i][0]){
      |                   ~^~~~~~~~~~~~~
bridges.cpp:91:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |             for(int k = 0 ; k<updates.size() ; k++){
      |                             ~^~~~~~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:120:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:121:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...