제출 #1067662

#제출 시각아이디문제언어결과실행 시간메모리
1067662oscar1f열쇠 (IOI21_keys)C++17
37 / 100
533 ms118892 KiB
#include<bits/stdc++.h> using namespace std; const int TAILLE_MAX=300*1000+5; int nbSom,nbAre,nbCompo; int clef[TAILLE_MAX]; int taille[TAILLE_MAX]; set<int> listeDispo[TAILLE_MAX]; vector<pair<int,int>> adjaInit[TAILLE_MAX]; int pere[TAILLE_MAX]; vector<int> somInter,ordre; int numCompo[TAILLE_MAX]; int dv[TAILLE_MAX]; vector<int> adja[TAILLE_MAX],adjaTrans[TAILLE_MAX]; vector<int> listeCompo[TAILLE_MAX]; int find(int pos) { if (pos!=pere[pos]) { pere[pos]=find(pere[pos]); } return pere[pos]; } void DFS1(int pos) { if (dv[pos]==0) { dv[pos]=1; for (int i:adja[pos]) { DFS1(i); } ordre.push_back(pos); } } void DFS2(int pos) { if (numCompo[pos]==0) { numCompo[pos]=nbCompo; listeCompo[nbCompo].push_back(pos); for (int i:adjaTrans[pos]) { DFS2(i); } } } void calcAdja() { somInter.clear(); for (int i=0;i<nbSom;i++) { adja[i].clear(); adjaTrans[i].clear(); if (find(i)==i) { somInter.push_back(i); numCompo[i]=0; dv[i]=0; } } for (int i=0;i<nbSom;i++) { for (auto j:adjaInit[i]) { if ((*listeDispo[find(i)].lower_bound(j.second))==j.second and find(i)!=find(j.first)) { //cout<<find(i)<<" "<<find(j.first)<<endl; adja[find(i)].push_back(find(j.first)); adjaTrans[find(j.first)].push_back(find(i)); } } } } vector<int> find_reachable(vector<int> r,vector<int> u,vector<int> v,vector<int> c) { nbSom=r.size(); nbAre=c.size(); for (int i=0;i<nbSom;i++) { clef[i]=r[i]; pere[i]=i; taille[i]=1; listeDispo[i].insert(clef[i]); } for (int i=0;i<nbAre;i++) { adjaInit[u[i]].push_back({v[i],c[i]}); adjaInit[v[i]].push_back({u[i],c[i]}); } int posMax=0,valMax,plusPetit; for (int loop=0;loop<7;loop++) { /*cout<<"NOUVEAU"<<endl; for (int i=0;i<nbSom;i++) { cout<<find(i)<<" "; } cout<<endl;*/ calcAdja(); ordre.clear(); for (int i:somInter) { DFS1(i); } reverse(ordre.begin(),ordre.end()); nbCompo=0; for (int i:ordre) { if (numCompo[i]==0) { nbCompo++; listeCompo[nbCompo].clear(); DFS2(i); } } somInter.clear(); for (int i=1;i<=nbCompo;i++) { /*cout<<i<<" : "; for (int j:listeCompo[i]) { cout<<j<<" "; } cout<<endl;*/ if ((int)listeCompo[i].size()>1) { valMax=0; for (int j:listeCompo[i]) { if (taille[j]>valMax) { valMax=taille[j]; posMax=j; } } somInter.push_back(posMax); for (int j:listeCompo[i]) { if (j!=posMax) { taille[posMax]+=taille[j]; pere[j]=posMax; for (int k:listeDispo[j]) { listeDispo[posMax].insert(k); } } } } else { somInter.push_back(listeCompo[i][0]); } } } plusPetit=TAILLE_MAX; for (int i:somInter) { if (adja[i].empty()) { plusPetit=min(plusPetit,taille[i]); } } vector<int> rep; for (int i=0;i<nbSom;i++) { if (adja[find(i)].empty() and taille[find(i)]==plusPetit) { rep.push_back(1); } else { rep.push_back(0); } } return rep; }
#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...