답안 #1111360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111360 2024-11-12T07:38:57 Z salmon Drivers (BOI24_drivers) C++14
100 / 100
144 ms 11768 KB
#include <bits/stdc++.h>
using namespace std;

int N;
int M;
int Q;
int parent[200100];
vector<pair<int,pair<int,int>>> edge;
int u,v,t;
vector<pair<pair<int,int>,pair<int,int>>> queries;
bool ans[200100];

int root(int i){
    if(parent[i] == i) return i;
    return parent[i] = root(parent[i]);
}

void connect(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return;

    parent[a] = b;
}

int main(){

    scanf(" %d",&N);
    scanf(" %d",&M);
    scanf(" %d",&Q);

    for(int i = 1; i <= N; i++) parent[i] = i;

    for(int i = 0; i < M; i++){
        scanf(" %d",&u);
        scanf(" %d",&v);
        scanf(" %d",&t);

        edge.push_back({t,{u,v}});
    }

    sort(edge.begin(),edge.end());

    for(int i = 0; i < Q; i++){
        scanf(" %d",&u);
        scanf(" %d",&v);
        scanf(" %d",&t);

        queries.push_back({{t,i},{u,v}});
    }

    sort(queries.begin(),queries.end());

    int it = 0;
    for(int i = 0; i < Q; i++){
        while(it != edge.size() && edge[it].first <= queries[i].first.first){
            connect(edge[it].second.first,edge[it].second.second);
            it++;
        }

        ans[queries[i].first.second] = (root(queries[i].second.second) == root(queries[i].second.first));
    }

    for(int i = 0; i < Q; i++){
        if(ans[i]) printf("TAIP\n");
        else printf("NE\n");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         while(it != edge.size() && edge[it].first <= queries[i].first.first){
      |               ~~~^~~~~~~~~~~~~~
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
Main.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf(" %d",&M);
      |     ~~~~~^~~~~~~~~~
Main.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf(" %d",&Q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf(" %d",&u);
      |         ~~~~~^~~~~~~~~~
Main.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf(" %d",&v);
      |         ~~~~~^~~~~~~~~~
Main.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf(" %d",&t);
      |         ~~~~~^~~~~~~~~~
Main.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf(" %d",&u);
      |         ~~~~~^~~~~~~~~~
Main.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf(" %d",&v);
      |         ~~~~~^~~~~~~~~~
Main.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf(" %d",&t);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 65 ms 6888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 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 2 ms 336 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 7 ms 1080 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 6 ms 908 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 65 ms 6888 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 4 ms 592 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 65 ms 6888 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 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 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 2 ms 336 KB Output is correct
16 Correct 3 ms 336 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 3 ms 760 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 7 ms 1080 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 6 ms 908 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 2 ms 336 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 4 ms 592 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 65 ms 6888 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 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 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 2 ms 336 KB Output is correct
16 Correct 3 ms 336 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 3 ms 760 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 7 ms 1080 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 6 ms 908 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 2 ms 336 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 4 ms 592 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 144 ms 11596 KB Output is correct
42 Correct 11 ms 1100 KB Output is correct
43 Correct 10 ms 888 KB Output is correct
44 Correct 17 ms 1160 KB Output is correct
45 Correct 13 ms 1276 KB Output is correct
46 Correct 9 ms 1040 KB Output is correct
47 Correct 107 ms 8108 KB Output is correct
48 Correct 12 ms 1100 KB Output is correct
49 Correct 96 ms 11768 KB Output is correct