Submission #96235

#TimeUsernameProblemLanguageResultExecution timeMemory
96235Retro3014Toll (APIO13_toll)C++17
16 / 100
2 ms376 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; }; //vector<S> gp[MAX_N+1]; 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; } } //cout<<idx<<endl; 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:52:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<edge.size(); i++){
               ~^~~~~~~~~~~~
toll.cpp:63:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<edge.size(); i++){
               ~^~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b); edge2.push_back({a, b});
   ~~~~~^~~~~~~~~~~~~~~~
toll.cpp:88:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a; scanf("%d", &a); P.push_back(a);
          ~~~~~^~~~~~~~~~
#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...