Submission #1302174

#TimeUsernameProblemLanguageResultExecution timeMemory
1302174damasenDrivers (BOI24_drivers)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n';

const int MOD = 1e9 + 7;
const int INF = 1e18;

vector<vector<pair<int, int>>> adj; vector<int> vis, parent; vector<vector<int>> path;

void bfs(int root){
    queue<int> q;
    q.push(root);
    vis[root] = 1;
    while(sz(q)){
        int node = q.front();
        int w = path[root][node];
        q.pop();
        for(auto go : adj[node]){
            int mx = max(w, go.second);
            if (vis[go.first]){
                if (mx < path[root][go.first]){
                    path[root][go.first] = mx;
                }
                continue;
            } 
            vis[go.first] = 1;
            path[root][go.first] = mx;
            q.push(go.first);
        }
    }
}

void solve() {
    int n, m, u;
    cin >> n >> m >> u;
    adj.resize(n+1); vis.assign(n+1, 0); path.assign(n+1, vector<int>(n+1, INF)); parent.assign(n+1, 0);
    while(m--){
        int x, y, w;
        cin >> x >> y >> w;
        adj[x].pb({y, w});
        adj[y].pb({x, w});
    }
    for(int i = 0; i <= n; i++){
        path[i][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        //vis.assign(n+1, 0); parent.assign(n+1, 0);
        bfs(i);
    }
    while(u--){
        int a, b, t;
        cin >> a >> b >> t;
        if (path[a][b] <= t) cout << "TAIP\n";
        else cout << "NE\n";
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
}
#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...