Submission #64205

#TimeUsernameProblemLanguageResultExecution timeMemory
64205gs14004두 로봇 (KOI18_robot)C++17
100 / 100
148 ms59748 KiB
#include <bits/stdc++.h> using namespace std; using pi = pair<int, int>; using lint = long long; const int MAXN = 255555; vector<pi> gph[MAXN]; vector<int> v; int n, s, e; int par[MAXN], pae[MAXN]; void dfs(int x, int p){ for(auto &i : gph[x]){ if(i.second != p){ par[i.second] = x; pae[i.second] = i.first; dfs(i.second, x); } } } int main(){ scanf("%d %d %d",&n,&s,&e); if(s == e){ puts("0"); return 0; } for(int i=0; i<n-1; i++){ int x, y, v; scanf("%d %d %d",&x,&y,&v); gph[x].push_back(pi(v, y)); gph[y].push_back(pi(v, x)); } dfs(s, -1); while(e != s){ v.push_back(pae[e]); e = par[e]; } cout << accumulate(v.begin(), v.end(), 0) - *max_element(v.begin(), v.end()) << endl; }

Compilation message (stderr)

robot.cpp: In function 'int main()':
robot.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&s,&e);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
robot.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x,&y,&v);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...