Submission #244629

# Submission time Handle Problem Language Result Execution time Memory
244629 2020-07-04T13:04:33 Z kimbj0709 Toll (BOI17_toll) C++14
7 / 100
37 ms 2048 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 50050
vector<int> ufds(maxn);
int find(int k){
    if(ufds[k]!=k){
        ufds[k] = find(ufds[k]);
    }
    return ufds[k];
}
void merge(int a,int b){
    int temp1 = find(a);
    int temp2 = find(b);
    ufds[min(temp1,temp2)] = max(temp1,temp2);
}
int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int k,n,m,o;
    for(int i=0;i<ufds.size();i++){
        ufds[i] = i;
    }
    cin >> k >> n >> m >> o;
    int input1,input2,input3;
    vector<int> prefix(maxn,0);
    for(int i=0;i<m;i++){
        cin >> input1 >> input2 >> input3;
        prefix[input1] += input3;
        merge(input1,input2);
    }
    for(int i=1;i<prefix.size();i++){
        prefix[i] += prefix[i-1];
    }
    for(int i=0;i<o;i++){
        cin >> input1 >> input2;
        int currsum = prefix[input2-1];
        if(input1!=0){
            currsum -= prefix[input1-1];
        }
        if(find(input1)!=find(input2)){
            cout << -1 << "\n";
        }
        else{
            cout << currsum << "\n";
        }
    }

}


Compilation message

toll.cpp: In function 'int32_t main()':
toll.cpp:21:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ufds.size();i++){
                 ~^~~~~~~~~~~~
toll.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<prefix.size();i++){
                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1280 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 6 ms 1188 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 23 ms 2048 KB Output is correct
9 Correct 22 ms 2048 KB Output is correct
10 Correct 8 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Incorrect 5 ms 1172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Incorrect 5 ms 1172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1280 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 6 ms 1188 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 23 ms 2048 KB Output is correct
9 Correct 22 ms 2048 KB Output is correct
10 Correct 8 ms 1280 KB Output is correct
11 Incorrect 37 ms 1152 KB Output isn't correct
12 Halted 0 ms 0 KB -