#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];
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++){
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
1280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
1152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
1280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |