Submission #798447

# Submission time Handle Problem Language Result Execution time Memory
798447 2023-07-30T17:38:07 Z Osplei Roadside Advertisements (NOI17_roadsideadverts) C++17
7 / 100
1000 ms 6448 KB
#include <bits/stdc++.h>
 
using namespace std;

int n, u, v, w, a, b, c, d, e, q;
vector <pair <int, int>> grafo[50005];
bool visto[50005];

int dfs(int nodo){

  visto[nodo]=true;

  int suma=0;

  for (auto i:grafo[nodo]) if (visto[i.first]==false) suma+=dfs(i.first)+i.second;

  return suma;
}

void SOLVE(){
  
  cin >> n;

  for (int i=0; i<n-1; i++){
    cin >> u >> v >> w;

    grafo[u].push_back({v, w});
    grafo[v].push_back({u, w});
  }

  cin >> q;

  while (q--){
    cin >> a >> b >> c >> d >> e;

    memset(visto, false, sizeof visto);

    cout << dfs(a) << "\n";
  }
}
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  //cin >> t;
  while(t--){
    SOLVE();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 6448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 132 ms 4132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1496 KB Output is correct
2 Execution timed out 1083 ms 6448 KB Time limit exceeded
3 Halted 0 ms 0 KB -