Submission #1266689

#TimeUsernameProblemLanguageResultExecution timeMemory
1266689ilovewaguriDrivers (BOI24_drivers)C++20
100 / 100
135 ms30904 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "DRIVERS" #define nl '\n' #define allofa(x,sz) x,x+sz+1 #define allof(x) x.begin(),x.end() #define allof1(x) x.begin()+1,x.end() #define mset(x,val) memset(x,val,sizeof(x)) #define couf(x) cout << fixed << setprecision(x) template<class T> T Abs(T &x) {return (x>=0 ? x : -x);}; template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;}; template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;}; typedef long long ll; const ll mod = (long long)1e9+7; const ll LINF = (long long)1e15; const int INF = (int)1e9; const int MAXN = (int)2e5+5; int n,m,q; void ccps() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if(fopen(NAME".inp","r")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } } struct DSU { int par[MAXN],power[MAXN]; void makeSet(int n) { for (int i = 1; i<=n; i++) { par[i]=i; power[i]=1; } } int find(int u) { return (u==par[u] ? u : par[u]=find(par[u])); } bool Union(int u, int v) { u=find(u);v=find(v); if(u==v) return false; if(power[u]<power[v]) swap(u,v); par[v]=u; power[u]+=power[v]; return true; } } dsu; struct edge { int u,v; ll w; bool operator <(const edge &ot) const { return w<ot.w; } }; signed main() { ccps(); cin >> n >> m >> q; vector<edge> edges(m+1),query(q+1); vector<int> weight; dsu.makeSet(n); for (int i = 1; i<=m; i++) { cin >> edges[i].u >> edges[i].v >> edges[i].w; } for (int i = 1; i<=q; i++) { cin >> query[i].u >> query[i].v >> query[i].w; } for (int i = 1; i<=m; i++) weight.push_back(edges[i].w); for (int i = 1; i<=q; i++) weight.push_back(query[i].w); sort(allof(weight)); weight.resize(unique(allof(weight))-weight.begin()); int zw = (int)weight.size(); vector<vector<int>> eByw(zw+1),qByw(zw+1); for (int i = 1; i<=m; i++) { int eID = lower_bound(allof(weight),edges[i].w)-weight.begin()+1; eByw[eID].push_back(i); } for (int i = 1; i<=q; i++) { int qID = lower_bound(allof(weight),query[i].w)-weight.begin()+1; qByw[qID].push_back(i); } vector<bool> res(q+1); for (int w = 0; w<=zw; w++) { for (int eID : eByw[w]) dsu.Union(edges[eID].u,edges[eID].v); for (int qID : qByw[w]) res[qID] = (dsu.find(query[qID].u)==dsu.find(query[qID].v)); } for (int i = 1; i<=q; i++) { cout << (res[i] ? "TAIP\n" : "NE\n"); } }

Compilation message (stderr)

Main.cpp: In function 'void ccps()':
Main.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(NAME".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...