Submission #1122629

#TimeUsernameProblemLanguageResultExecution timeMemory
1122629ntdaccodeReconstruction Project (JOI22_reconstruction)C++17
0 / 100
1 ms324 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define int long long #define pb push_back using namespace std; typedef pair<int,int> ii; typedef tuple<int,int,int> tp; const int M = 1e6 + 10; const int N = 1e3 + 10; const int mod = 1e9 + 7; int n, m, q, uu[M], vv[M], ww[M]; int id[M]; int finded(int u) { return id[u] < 0 ? u : id[u] = finded(id[u]); } bool unioned(int u,int v) { u = finded(u); v = finded(v); if(v == u) return false; if(id[u] > id[v]) swap(u,v); id[u] += id[v]; id[v] = u; return true; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> m ; for(int i = 1;i <= m; i++) { cin >> uu[i] >> vv[i] >> ww[i]; } cin >> q; while(q--) { int x; cin >> x; vector<tp> edge; int kq = 0; for(int i = 1;i <= m; i++) edge.pb({abs(ww[i] - x),uu[i],vv[i]}); sort(edge.begin(),edge.end()); for(int i = 1;i <= n; i++) id[i] = -1; int v,u,w; for(int i = 0;i < edge.size() - 1; i++) { tie(w,u,v) = edge[i]; if(unioned(u,v)) kq += w; } cout << kq << "\n"; } }

Compilation message (stderr)

reconstruction.cpp: In function 'int32_t main()':
reconstruction.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
reconstruction.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen(task".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...
#Verdict Execution timeMemoryGrader output
Fetching results...