Submission #1111367

# Submission time Handle Problem Language Result Execution time Memory
1111367 2024-11-12T07:47:01 Z zhehan Drivers (BOI24_drivers) C++17
100 / 100
301 ms 11968 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> ii;

typedef pair<int,ii> iii;

typedef pair<iii,int> iiii;

int ufds[200000];

int f(int a){
    if(ufds[a]==a){
        return a;
    }
    return ufds[a]=f(ufds[a]);
}

void join(int a,int b){
    ufds[f(a)]=f(b);
}

int main()
{
    int n,m,u,a,b,c;
    cin>>n>>m>>u;
    for(int i=0;i<=n;++i){
        ufds[i]=i;
    }
    priority_queue<iii,vector<iii>,greater<iii>>roads;
    for(int i=0;i<m;++i){
        cin>>a>>b>>c;
        roads.push(iii(c,ii(a,b)));
    }
    priority_queue<iiii,vector<iiii>,greater<iiii>> qrys;
    for(int i=0;i<u;++i){
        cin>>a>>b>>c;
        qrys.push(iiii(iii(c,ii(a,b)),i));
    }
    bool arr[u];
    while(!qrys.empty()){
        iiii qry=qrys.top();
        qrys.pop();
        int p=qry.first.first;
        int a=qry.first.second.first;
        int b=qry.first.second.second;
        while(!roads.empty()&&roads.top().first<=p){
            iii r=roads.top();
            int ca=r.second.first;
            int cb=r.second.second;
            join(ca,cb);
            roads.pop();
        }
        arr[qry.second]=f(a)==f(b);
    }
    for(int i=0;i<u;++i){
        if(arr[i]){
            cout<<"TAIP"<<'\n';
        }else{
            cout<<"NE"<<'\n';
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 128 ms 6776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 3 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 4 ms 336 KB Output is correct
12 Correct 5 ms 592 KB Output is correct
13 Correct 3 ms 336 KB Output is correct
14 Correct 5 ms 728 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 15 ms 908 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 12 ms 980 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 128 ms 6776 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 4 ms 336 KB Output is correct
10 Correct 6 ms 592 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 128 ms 6776 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
16 Correct 4 ms 336 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 3 ms 336 KB Output is correct
19 Correct 5 ms 728 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 15 ms 908 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 12 ms 980 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 4 ms 336 KB Output is correct
35 Correct 6 ms 592 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 1 ms 452 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 128 ms 6776 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
16 Correct 4 ms 336 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 3 ms 336 KB Output is correct
19 Correct 5 ms 728 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 15 ms 908 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 12 ms 980 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 4 ms 336 KB Output is correct
35 Correct 6 ms 592 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 1 ms 452 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 301 ms 11700 KB Output is correct
42 Correct 18 ms 1144 KB Output is correct
43 Correct 20 ms 908 KB Output is correct
44 Correct 31 ms 1356 KB Output is correct
45 Correct 26 ms 1100 KB Output is correct
46 Correct 16 ms 1040 KB Output is correct
47 Correct 237 ms 7976 KB Output is correct
48 Correct 20 ms 1100 KB Output is correct
49 Correct 265 ms 11968 KB Output is correct