Submission #205773

#TimeUsernameProblemLanguageResultExecution timeMemory
205773ly20Toll (BOI17_toll)C++17
7 / 100
56 ms2808 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 512345; long long v[MAXN]; int pai[MAXN], sz[MAXN]; int find(int a) { if(a == pai[a]) return a; return pai[a] = find(pai[a]); } void une(int a, int b) { a = find(a); b = find(b); if(sz[a] > sz[b]) swap(a, b); pai[a] = b; sz[b] += sz[a]; } int main() { int k, n, m, o; scanf("%d %d %d %d", &k, &n, &m, &o); for(int i = 0; i < n; i++) { pai[i] = i; sz[i] = 1; } for(int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); scanf("%lld", &v[b]); une(a, b); } for(int i = 1; i < n; i++) { v[i] += v[i - 1]; } for(int i = 0; i < o; i++) { int a, b; scanf("%d %d", &a, &b); if(find(a) != find(b)) { printf("-1\n"); } else if(a < b) printf("%lld\n", v[b] - v[a]); else printf("-1\n"); } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d", &k, &n, &m, &o);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
toll.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &v[b]);
   ~~~~~^~~~~~~~~~~~~~~
toll.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
#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...