Submission #764941

# Submission time Handle Problem Language Result Execution time Memory
764941 2023-06-24T06:45:55 Z vjudge1 Roadside Advertisements (NOI17_roadsideadverts) C++17
47 / 100
1000 ms 52756 KB
#include <bits/stdc++.h>
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define ent '\n'
#define f first
#define s second

using namespace std;
typedef long long ll;
typedef pair < int, int> pii;
typedef pair < ll, ll > pll;

const int maxn = 2e6 + 100;
const int mod = 1e9 + 7;
const int INF = 1e9;
const int LOG = 20;
const int K = 400;
const int P = 31;

int n, m;
vector < pii > g[maxn];
int ans;
int a, b, c, d, e;

int dfs(int v, int pa, int cal){
    bool ok = 0;
    if(v == b || v == c || v == d || v == e){
        ans += cal;
        ok = 1;
    }
    for(pii to: g[v]){
        if(to.f == pa)continue;
        int c;
        if(!ok)c = dfs(to.f, v, to.s + cal);
        else c = dfs(to.f, v, to.s);
        if(c){
            ok = 1;
        }
    }
    return ok;
}

void solve(){
    cin >> n;
    for(int i = 1;i < n;i++){
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    cin >> m;
    for(int i = 1;i <= m;i++){
        cin >> a >> b >> c >> d >> e;
        dfs(a, -1, 0);
        cout << ans << ent;
        ans = 0;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int i = 1;i <= T;i++){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 52756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 136 ms 49140 KB Output is correct
2 Correct 227 ms 52140 KB Output is correct
3 Correct 226 ms 52096 KB Output is correct
4 Correct 225 ms 52092 KB Output is correct
5 Correct 212 ms 52044 KB Output is correct
6 Correct 207 ms 52044 KB Output is correct
7 Correct 207 ms 52040 KB Output is correct
8 Correct 215 ms 52100 KB Output is correct
9 Correct 219 ms 52100 KB Output is correct
10 Correct 212 ms 52032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47188 KB Output is correct
2 Execution timed out 1060 ms 52756 KB Time limit exceeded
3 Halted 0 ms 0 KB -