Submission #128242

#TimeUsernameProblemLanguageResultExecution timeMemory
128242claudyBridges (APIO19_bridges)C++14
14 / 100
149 ms10496 KiB
//# pragma GCC optimize("Ofast,no-stack-protector") //# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") # pragma GCC optimize("Ofast") # pragma GCC optimization ("unroll-loops") # include "bits/stdc++.h" std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}}; # define ll long long # define clock (clock() * 1000.0 / CLOCKS_PER_SEC) # define rc(s) return cout << s,0 # define rcg(s) cout << s;exit(0) # define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); # define db(x) cerr << #x << " = " << x << '\n' # define pb push_back # define mp make_pair # define all(s) s.begin(),s.end() # define sz(x) (int)((x).size()) //# define int ll using namespace std; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # define LOCAL # define sim template < class c # define ris return * this # define dor > debug & operator << # define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " int gcd(int a, int b) { if(b) return gcd(b,a%b); return a; }mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int n,m,q,p[1 << 17],sze[1 << 17],ans[1 << 17]; vector<pair<int,pair<int,int>>>edges; vector<pair<int,int>>vec[1 << 17]; int find(int x) { if(p[x] == x) return x; return p[x] = find(p[x]); } void unite(int a,int b) { a = find(a); b = find(b); if(a == b) return ; if(sze[a] > sze[b]) swap(a,b); p[a] = b; sze[b] += sze[a]; } int32_t main(){_ //freopen("input","r",stdin); cin >> n >> m; for(int i = 1;i <= m;i++) { int a,b,c; cin >> a >> b >> c; edges.pb(mp(c,mp(a,b))); } sort(edges.begin(),edges.end()); cin >> q; for(int i = 1;i <= q;i++) { int t,s,w; cin >> t >> s >> w; vec[upper_bound(edges.begin(),edges.end(),mp(w - 1,mp(2000000000,2000000000))) - edges.begin()].pb(mp(s,i)); } for(int i = 1;i <= n;i++) { p[i] = i; sze[i] = 1; } for(int i = sz(edges) - 1;i >= 0;i--) { unite(edges[i].second.first,edges[i].second.second); for(auto it : vec[i]) { ans[it.second] = sze[find(it.first)]; } } for(int i = 1;i <= q;i++) cout << max(1,ans[i]) << '\n'; return 0; }

Compilation message (stderr)

bridges.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 # pragma GCC optimization ("unroll-loops")
#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...