Submission #568797

#TimeUsernameProblemLanguageResultExecution timeMemory
568797almothana05Bridges (APIO19_bridges)C++14
27 / 100
215 ms24860 KiB
#include<bits/stdc++.h> #define mod 1000000007 #define inf 10000000000000000 using namespace std; vector<vector<int> >mst , q; pair<int , int>f[200000]; vector<vector<int> >edge; vector<pair<int , int> >gr[100000]; int erg[200000] ,vis[100000] , erge; void dfs(int x , int cmp){ // cout << x << ' ' << erg << "\n"; vis[x] = 1; erge++; for(int i = 0 ; i < gr[x].size() ; i++){ int kind = gr[x][i].first , val = gr[x][i].second; // cout << x << ' ' << kind << ' ' << val << "\n"; if(vis[kind] == 0 && val >= cmp){ dfs(kind , cmp); } } } int fater(int x){ if(x == f[x].first){ return x; } f[x].first = fater(f[x].first); return f[x].first; } void merge(int z , int x , int y){ while(q.size() && q[q.size() - 1][0] > z){ erg[q[q.size() - 1][2]] = f[fater(q[q.size() - 1][1])].second; q.pop_back(); } if(fater(x) != fater(y)){ f[fater(x)].second += f[fater(y)].second; f[fater(y)].first = fater(x); } } int main(){ for(int i = 0 ; i < 200000 ; i++){ f[i] = {i , 1}; } ios_base::sync_with_stdio(false); cin.tie(NULL); int menge , numm , nummer , ed , cmp , comp ;; cin >> menge >> ed; for(int i = 0 ; i < ed ; i++){ cin >> numm >> nummer >> cmp; mst.push_back({cmp , numm , nummer}); gr[numm].push_back({nummer , cmp}); gr[nummer].push_back({numm , cmp}); edge.push_back({numm , gr[numm].size() - 1 , nummer , gr[nummer].size() - 1}); } sort(mst.begin() , mst.end()); int que ; cin >> que; if(menge <= 1000 && que <= 10000 && ed <= 1000){ while(que--){ // cout << "ja\n"; cin >> numm; if(numm == 1){ cin >> numm >> nummer; numm--; gr[edge[numm][0]][edge[numm][1]].second = nummer; gr[edge[numm][2]][edge[numm][3]].second = nummer; // cout << *edge[numm].first << "\n"; // for(int i = 0 ; i < gr[1].size() ; i++){ // cout << gr[1][i].second << ' '; // } // cout << "\n"; } else{ cin >> numm >> nummer; erge = 0; dfs(numm , nummer); cout << erge << "\n"; for(int i = 0 ; i <= menge ; i++){ vis[i] = 0; } } } return 0; } for(int i = 0 ; i < que ; i++){ cin >> cmp >> numm >> nummer; q.push_back({nummer , numm , i}); } sort(q.begin() , q.end()); for(int i = ed - 1; i >= 0 ; i--){ merge(mst[i][0] , mst[i][1] , mst[i][2]); } while(q.size() ){ erg[q[q.size() - 1][2]] = f[fater(q[q.size() - 1][1])].second; q.pop_back(); } for(int i = 0 ; i < que ; i++){ cout << erg[i] << "\n"; } }

Compilation message (stderr)

bridges.cpp: In function 'void dfs(int, int)':
bridges.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |    for(int i = 0 ; i < gr[x].size() ; i++){
      |                    ~~^~~~~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:54:46: warning: narrowing conversion of '(gr[numm].std::vector<std::pair<int, int> >::size() - 1)' from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   54 |       edge.push_back({numm , gr[numm].size() - 1 , nummer , gr[nummer].size() - 1});
      |                              ~~~~~~~~~~~~~~~~^~~
bridges.cpp:54:46: warning: narrowing conversion of '(gr[numm].std::vector<std::pair<int, int> >::size() - 1)' from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
bridges.cpp:54:79: warning: narrowing conversion of '(gr[nummer].std::vector<std::pair<int, int> >::size() - 1)' from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   54 |       edge.push_back({numm , gr[numm].size() - 1 , nummer , gr[nummer].size() - 1});
      |                                                             ~~~~~~~~~~~~~~~~~~^~~
bridges.cpp:54:79: warning: narrowing conversion of '(gr[nummer].std::vector<std::pair<int, int> >::size() - 1)' from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
bridges.cpp:46:43: warning: unused variable 'comp' [-Wunused-variable]
   46 |    int menge , numm , nummer , ed , cmp , comp ;;
      |                                           ^~~~
#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...