제출 #433783

#제출 시각아이디문제언어결과실행 시간메모리
433783Mounir다리 (APIO19_bridges)C++14
0 / 100
399 ms17228 KiB
#include <bits/stdc++.h> #define chmax(x, v) x = max(x, v) #define pii pair<int, int> #define pb push_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define int long long using namespace std; const int N = (1 << 18), B = 18; struct Arete { int noeud, voisin, poids; bool isArete; bool operator < (const Arete &autre) const { if (poids != autre.poids) return poids < autre.poids; return isArete; } }; int numNoeud[N], numVoisin[N]; int noeudArete[N], voisinArete[N]; bool vu[N]; int ens[N], taille[N]; int getEns(int noeud){ if (ens[noeud] != noeud) ens[noeud] = getEns(ens[noeud]); return ens[noeud]; } vector<pii> voisins[N]; int ancetres[N][B], maxi[N][B]; int prof[N]; int ans[N]; signed main(){ int nNoeuds, nAretes; cin >> nNoeuds >> nAretes; vector<Arete> aretes; for (int iArete = 0; iArete < nAretes; ++iArete){ int noeud, voisin, poids; cin >> noeud >> voisin >> poids; --noeud, --voisin; aretes.pb({noeud, voisin, poids, true}); } int nReqs; cin >> nReqs; for (int iReq = 0; iReq < nReqs; ++iReq){ int type, noeud, poids; cin >> type >> noeud >> poids; aretes.pb({noeud - 1, iReq, poids, false}); } for (int noeud = 0; noeud < nNoeuds; ++noeud) ens[noeud] = noeud, taille[noeud] = 1; sort(all(aretes)); for (Arete& arete : aretes){ if (arete.isArete){ int a = arete.noeud, b = arete.voisin; arete.noeud = getEns(arete.noeud); arete.voisin = getEns(arete.voisin); if (arete.noeud != arete.voisin){ ens[arete.noeud] = arete.voisin; taille[arete.voisin] += taille[arete.noeud]; voisins[a].pb({b, arete.poids}); voisins[b].pb({a, arete.poids}); } } else ans[arete.voisin] = taille[getEns(arete.noeud)]; } for (int iReq = 0; iReq < nReqs; ++iReq){ cout << ans[iReq] << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...