Submission #1269219

#TimeUsernameProblemLanguageResultExecution timeMemory
1269219G_thang_dizz_lenhiDrivers (BOI24_drivers)C++17
0 / 100
1 ms324 KiB
#include<bits/stdc++.h>
typedef int ii;
typedef long long ll;

using namespace std;

const string name = "DRIVERS";
const ii MOD = 1e9 + 7;
const ii N = 2e5 + 10;

void INP(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (fopen((name + ".inp").c_str(),"r")){
        freopen((name + ".inp").c_str(),"r",stdin);
        freopen((name + ".out").c_str(),"w",stdout);
    }
    else{
        freopen(".inp", "r", stdin);
    }
}

struct node{
    ii u, v, w;
    ii type;


    bool operator<(const node &other){
        if (w != other.w) return w < other.w;
        return type < other.type;
    }
};

ii n, m, q;
vector<node> a;
ii par[N];
bool res[N];

void init(){
    for (ii i = 1;i <= n;i++) par[i] = i;
}

ii find_par(ii u){
    return (u == par[u] ? u : par[u] = find_par(par[u]));
}

void connect(ii u,ii v){
    u = find_par(u);
    v = find_par(v);
    if (u != v) par[u] = v;
}

int main(){
    INP();
    cin >> n >> m >> q;
    ii u, v, w, type;
    for (ii i = 0;i < m;i++){
        cin >> u >> v >> w;
        a.push_back({u, v, w, 0});
    }

    for (ii i = 1;i <= q;i++){
        cin >> u >> v >> w;
        a.push_back({u, v, w, i});
    }

    init();

    sort(a.begin(), a.end());
    for (ii i = 0;i < a.size();i++){
        u = a[i].u;
        v = a[i].v;
        w = a[i].w;
        type = a[i].type;
        cerr << u << " " << v << " " << " " << w << " " << type << "\n";
        if (type == 0){
            connect(u, v);
        }
        else{
            res[type] = (find_par(u) == find_par(v));
        }
    }

    for (ii i = 1;i <= q;i++){
        if (res[i]){
            cout << "TAIP\n";
        }
        else{
            cout << "NE\n";
        }
    }

    return 0;
}

//NGT 1600-2000 cf
//1/200 hard quests

Compilation message (stderr)

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