Submission #240145

#TimeUsernameProblemLanguageResultExecution timeMemory
240145wiwihoBridges (APIO19_bridges)C++14
14 / 100
124 ms9192 KiB
//#define NDEBUG #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define iceil(a, b) ((a + b - 1) / b) #define tomax(a, b) (a = max(a, b)) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} //#define TEST using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } vector<int> dsu; vector<int> sz; int findDSU(int a){ if(dsu[a] == a) return a; dsu[a] = findDSU(dsu[a]); return dsu[a]; } void unionDSU(int a, int b){ a = findDSU(a); b = findDSU(b); if(a == b) return; sz[b] += sz[a]; dsu[a] = b; } int main(){ StarBurstStream int n, m; cin >> n >> m; vector<pair<int, pii>> e; for(int i = 1; i <= m; i++){ int u, v, w; cin >> u >> v >> w; e.eb(mp(w, mp(u, v))); } dsu.resize(n + 1); sz.resize(n + 1, 1); for(int i = 1; i <= n; i++) dsu[i] = i; int q; cin >> q; vector<pair<pii, int>> qry; for(int i = 0; i < q; i++){ int t; cin >> t; int s, wl; cin >> s >> wl; qry.eb(mp(mp(wl, s), i)); } gsort(e); gsort(qry); vector<pii> ans; int now = 0; for(auto i : qry){ while(now < e.size() && e[now].F >= i.F.F){ unionDSU(e[now].S.F, e[now].S.S); now++; } ans.eb(mp(i.S, sz[findDSU(i.F.S)])); } lsort(ans); for(auto i : ans) cout << i.S << "\n"; return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:103:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(now < e.size() && e[now].F >= i.F.F){
               ~~~~^~~~~~~~~~
#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...