# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
568759 | almothana05 | 다리 (APIO19_bridges) | C++14 | 3088 ms | 25116 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 10000000000000000
using namespace std;
vector<vector<int> >edge , q ,mst;
vector<pair<int , int> >gr[100000];
int erg , vis[100000] , erge[100010] ;
pair<int , int> f[100000];
void dfs(int x , int cmp){
// cout << x << ' ' << erg << "\n";
vis[x] = 1;
erg++;
for(int i = 0 ; i < gr[x].size() ; i++){
int kind = gr[x][i].first , val = gr[x][i].second;
// cout << x << ' ' << kind << ' ' << val << "\n";
if(vis[kind] == 0 && val >= cmp){
dfs(kind , cmp);
}
}
}
int fater(int x){
if(f[x].first == x){
return x;
}
f[x].first = fater(f[x].first);
return f[x].first;
}
void merge(int z , int x , int y){
// if(z == 1){
// cout << "ja\n";
// }
while(q.size() > 0 && z < q[q.size() - 1][0]){
// cout << z <<' ' << q[q.size() - 1][0] << "\n" << q.size() << "\n";
// cout << q[q.size() - 1][1] << ' ' << f[fater(q[q.size() - 1][1])].first << "\n";
erge[q[q.size() - 1][2]] = f[fater(q[q.size() - 1][1])].second;
q.pop_back();
}
if(fater(x) != fater(y)){
// cout << x << ' ' << y << "\n\n";
f[fater(x)].second += f[fater(y)].second;
f[fater(y)].first = fater(x);
}
}
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int menge , numm , nummer , ed , cmp , comp ;;
cin >> menge >> ed;
for(int i = 0 ; i <= menge ; i++){
f[i] = {i , 1};
}
for(int i = 0 ; i < ed ; i++){
cin >> numm >> nummer >> cmp;
gr[numm].push_back({nummer , cmp});
gr[nummer].push_back({numm , cmp});
edge.push_back({numm , gr[numm].size() - 1 , nummer , gr[nummer].size() - 1});
mst.push_back({cmp , numm , nummer});
}
int que;
cin >> que;
if(que > 10000 && menge > 1000){
sort(mst.begin() , mst.end());
for(int i = 0 ; i < que ; i++){
cin >> numm >> numm >> nummer;
q.push_back({nummer , numm , i});
}
sort(q.begin() , q.end());
for(int i = ed - 1 ; i >= 0 ; i--){
// numm = mst[i][];
merge(mst[i][0] , mst[i][1] , mst[i][2]);
}
while(q.size() > 0 ){
// cout << q[q.size() - 1][1] << ' ' << f[fater(q[q.size() - 1][1])].first << "\n";
erge[q[q.size() - 1][2]] = f[fater(q[q.size() - 1][1])].second;
q.pop_back();
}
for(int i = 0 ; i < que ; i++){
cout << erge[i] << "\n";;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
while(que--){
// cout << "ja\n";
cin >> numm;
if(numm == 1){
cin >> numm >> nummer;
numm--;
gr[edge[numm][0]][edge[numm][1]].second = nummer;
gr[edge[numm][0]][edge[numm][1]].second = nummer;
}
else{
cin >> numm >> nummer;
erg = 0;
dfs(numm , nummer);
cout << erg << "\n";
for(int i = 0 ; i <= menge ; i++){
vis[i] = 0;
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |