Submission #1044960

#TimeUsernameProblemLanguageResultExecution timeMemory
1044960vjudge1Bridges (APIO19_bridges)C++17
13 / 100
61 ms19200 KiB
#pragma GCC optimize("unroll-loops,Ofast,O3") #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define spc << " " << #define endl "\n" #define all(x) x.begin(), x.end() #define int long long #define ii pair<long long,int> #define vi vector<int> #define vii vector<ii> #define st first #define nd second #define inf 1e15 #define MOD 1000000007 #define MX 50005 using namespace std; vii edges[MX]; int wei[2*MX]; int vis[MX]; int dfs(int node, int lim){ vis[node]=1; int res=1; for(auto p:edges[node]){ if(vis[p.st] || wei[p.nd]<lim) continue; res += dfs(p.st, lim); } return res; } int lie[MX], siz[MX]; int find(int x){ if(lie[x]==x) return x; return lie[x] = find(lie[x]); } bool unite(int x, int y){ x=find(x); y=find(y); if(x==y) return false; siz[x]+=siz[y]; lie[y]=lie[x]; } void solve(){ int n,m,q; cin >> n >> m; vector<array<int, 3>> ws; for(int i=1; i<=m; i++){ int a,b,c; cin >> a >> b >> c; edges[a].pb({b,i}); edges[b].pb({a,i}); wei[i]=c; ws.pb({c, a, b}); } cin >> q; if(n<=1000 && m<=1000 && q<=10000){ for(int i=1; i<=q; i++){ int a,b,c; cin >> a >> b >> c; if(a==1){ wei[b]=c; } else{ for(int i=1; i<=n; i++) vis[i]=0; cout << dfs(b, c) << endl; } } return; } for(int i=1; i<=n; i++){ lie[i]=i; siz[i]=1; } vector<array<int, 3>> qs; for(int i=1; i<=q; i++){ int a,b,c; cin >> a >> b >> c; if(a==1) return; qs.pb({c,b,i}); } int ans[q+1]; sort(all(qs), greater<array<int, 3>>()); sort(all(ws), greater<array<int, 3>>()); int heh=0; for(auto p:qs){ while(heh<ws.size() && ws[heh][0]>=p[0]){ unite(ws[heh][1], ws[heh][2]); heh++; } ans[p[2]] = siz[find(p[1])]; } for(int i=1; i<=q; i++) cout << ans[i] << endl; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif /*freopen("nondec.in","r",stdin); freopen("nondec.out","w",stdout);*/ int t=1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

bridges.cpp: In function 'void solve()':
bridges.cpp:84:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         while(heh<ws.size() && ws[heh][0]>=p[0]){
      |               ~~~^~~~~~~~~~
bridges.cpp: In function 'bool unite(long long int, long long int)':
bridges.cpp:41:11: warning: control reaches end of non-void function [-Wreturn-type]
   41 |     lie[y]=lie[x];
      |     ~~~~~~^~~~~~~
#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...