Submission #764940

# Submission time Handle Problem Language Result Execution time Memory
764940 2023-06-24T06:44:47 Z vjudge1 Roadside Advertisements (NOI17_roadsideadverts) C++17
0 / 100
1 ms 684 KB
#include <bits/stdc++.h>
#define ibase ios::sync_with_stdio(false); cin.tie(0);  cout.tie(0)
#define pb push_back
#define ff first
#define int long long
#define ss second
using namespace std;
const int N = 1e3 + 3;
const int MOD = 1e9 + 7;
int a[N], ans[N], pos[N], cnt = 0, was[N], was1[N];
vector < pair < int, int > > g[N];
void dfs(int v){
    cnt++;
    for(auto to : g[v]){
        a[cnt] = to.ss;
        pos[to.ff] = cnt;
        dfs(to.ff);
    }
}
void solve(){
    int n, sum = 0;
    cin >> n;
    set < int > s;
    for(int i=1; i<n; i++){
        int x, y, cost;
        cin >> x >> y >> cost;
        was[y] = 1;
        was1[x] = 1;
        s.insert(x);
        s.insert(y);
        sum += cost;
        g[x].pb(make_pair(y, cost));
    }
    int z;
    for(auto to : s){
        if(was[to] == 0){
            pos[to] = 1;
            z = to;
        }
        if(was1[to] == 0){
            pos[to] = s.size();
        }
    }
    dfs(z);
    for(int i=1; i<=s.size(); i++){
        ans[i] = ans[i - 1] + a[i];
    }
    cout << endl;
    int q;
    cin >> q;
    while(q--){
        int a, b, c, d, e;
        cin >> a >> b >> c >> d >> e;
        int l, r;
        l = min({pos[a], pos[b], pos[c], pos[d], pos[e]});
        r = max({pos[a], pos[b], pos[c], pos[d], pos[e]});
        cout << ans[r] - ans[l] << endl;
    }
}
signed main() {
    ibase;
    int t = 1;
    //freopen("floor4.in", "r", stdin);
    //freopen("floor4.out", "w", stdout);
    //cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

roadsideadverts.cpp: In function 'void solve()':
roadsideadverts.cpp:45:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::set<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=1; i<=s.size(); i++){
      |                  ~^~~~~~~~~~
roadsideadverts.cpp:44:8: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     dfs(z);
      |     ~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -