Submission #1266615

#TimeUsernameProblemLanguageResultExecution timeMemory
1266615ilovewaguriDrivers (BOI24_drivers)C++20
10 / 100
32 ms6472 KiB
#include<bits/stdc++.h>
using namespace std;
#define NAME "DRIVERS"
#define nl '\n'
#define allofa(x,sz) x,x+sz+1
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,val) memset(x,val,sizeof(x))
#define couf(x) cout << fixed << setprecision(x)
template<class T> T Abs(T &x) {return (x>=0 ? x : -x);};
template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;};
template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;};
typedef long long ll;
typedef pair<ll,int> pli;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e15;
const int INF = (int)1e9;
const int MAXN = (int)2e5+5;
vector<pli> graph[MAXN];
bool isSub1;
int n,m,q;

void ccps() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    if(fopen(NAME".inp","r")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
}

namespace subtask1 {
    const int N = (int)1e4+5;
    int w;

    bool check() {
        return isSub1 and 1<=n and n<=1e4 and 1<=m and m<=1e4;
    }

    struct DSU {
        int power[MAXN],parent[MAXN];

        void makeSet(int n) {
            for (int i = 1; i<=n; i++) {
                parent[i]=i;
                power[i]=1;
            }
        }

        int find(int u) {
            if(u==parent[u]) return u;
            return parent[u] = find(parent[u]);
        }

        void Union(int u, int v) {
            u=find(u);v=find(v);
            if(u==v) return;
            if(power[u]<power[v]) swap(u,v);
            parent[v]=u;
            power[u]+=power[v];
        }
    } dsu;

    void sol() {
        while(q--) {
            int x,y,t; cin >> x >> y >> t;
            if(w>t) {
                cout << "NE" << nl;
                continue;
            }
            x=dsu.find(x);y=dsu.find(y);
            cout << (x==y ? "TAIP" : "NE") << nl;
        }
    }
}

signed main() {
    ccps();
    cin >> n >> m >> q;
    subtask1::dsu.makeSet(n);
    int firstW = -1; isSub1=true;
    for (int i = 1; i<=m; i++) {
        int u,v; ll w; cin >> u >> v >> w;
        graph[u].push_back({w,v});
        graph[v].push_back({w,u});
        if(firstW==-1) firstW=w;
        else if(firstW!=w) isSub1 = false;
        subtask1::dsu.Union(u,v);
    }
    if(subtask1::check()) {subtask1::w = firstW;subtask1::sol();}
    else cout << "NE";
}

Compilation message (stderr)

Main.cpp: In function 'void ccps()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...