Submission #956194

#TimeUsernameProblemLanguageResultExecution timeMemory
956194Trisanu_DasToll (APIO13_toll)C++17
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <stdio.h> using namespace std; #define MAX_N 100000 #define MAX_M 300000 typedef long long ll; int N, M, K; struct EDGE{ EDGE (int x, int y, int z) : x(x), y(y), z(z) {} int x, y, z; bool operator <(const EDGE &a)const{ return z<a.z; } }; vector<EDGE> edge; struct EDGE2{ EDGE2 (int x, int y) : x(x), y(y) {} int x, y; }; vector<EDGE2> edge2; vector<int> P; struct S{ S (int idx, int data) : idx(idx), data(data) {} int idx, data; }; int g[MAX_N+1]; void init(){ for(int i=1; i<=N; i++) g[i] = i; } int find_g(int x){ if(x==g[x]) return x; return g[x] = find_g(g[x]); } void union_g(int x, int y){ x = find_g(x); y = find_g(y); g[x] = y; } bool use[MAX_M+1]; void solve1(){ int idx = -1; init(); for(int i=0; i<edge.size(); i++){ if(find_g(edge[i].x)==find_g(edge[i].y)) continue; union_g(edge[i].x, edge[i].y); use[i] = true; if(idx==-1 && find_g(edge2[0].x)==find_g(edge2[0].y)){ idx = i; use[i] = false; } } init(); for(int i=0; i<edge.size(); i++){ if(!use[i]) continue; union_g(edge[i].x, edge[i].y); } ll ans=0; for(int i=1; i<=N; i++){ if(find_g(i)==find_g(1)) continue; ans += (ll)P[i]; } ans *= (ll)edge[idx].z; printf("%lld", ans); } int main(){ scanf("%d%d%d", &N, &M, &K); for(int i=0; i<M; i++){ int a, b, c; scanf("%d%d%d", &a, &b, &c); edge.push_back({a, b, c}); }sort(edge.begin(), edge.end()); for(int i=0; i<K; i++){ int a, b; scanf("%d%d", &a, &b); edge2.push_back({a, b}); }P.push_back(0); for(int i=1; i<=N; i++) int a; scanf("%d", &a); P.push_back(a); if(N<=10 && M<=20 && K==1){ solve1(); } return 0; }

Compilation message (stderr)

toll.cpp: In function 'void solve1()':
toll.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<EDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i=0; i<edge.size(); i++){
      |               ~^~~~~~~~~~~~
toll.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<EDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i=0; i<edge.size(); i++){
      |               ~^~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:85:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   85 |  for(int i=1; i<=N; i++) int a; scanf("%d", &a); P.push_back(a);
      |  ^~~
toll.cpp:85:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |  for(int i=1; i<=N; i++) int a; scanf("%d", &a); P.push_back(a);
      |                                 ^~~~~
toll.cpp:85:30: warning: unused variable 'a' [-Wunused-variable]
   85 |  for(int i=1; i<=N; i++) int a; scanf("%d", &a); P.push_back(a);
      |                              ^
toll.cpp:85:46: error: 'a' was not declared in this scope
   85 |  for(int i=1; i<=N; i++) int a; scanf("%d", &a); P.push_back(a);
      |                                              ^
toll.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  scanf("%d%d%d", &N, &M, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |   scanf("%d%d%d", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |   scanf("%d%d", &a, &b); edge2.push_back({a, b});
      |   ~~~~~^~~~~~~~~~~~~~~~