이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MAXN = 501;
int adjMatrix[MAXN][MAXN],dsu_parent[MAXN],N;
int e1[MAXN*MAXN],e2[MAXN*MAXN];
vi arestas_certas,arestas_dsu;
int dsu_find(int x){
if(x == dsu_parent[x]) return x;
return dsu_parent[x] = dsu_find(dsu_parent[x]);
}
void dsu_join(int x,int y){
x = dsu_find(x);
y = dsu_find(y);
if(x == y) return;
if(x > y) swap(x,y);
dsu_parent[y] = x;
}
void dsu_reset(){
for(int i = 0;i<N;i++) dsu_parent[i] = i;
}
void processa(int x){
dsu_reset();
arestas_dsu.clear();
for(int i = 0;i<N;i++){
if(i == x) continue;
for(int j = 0;j<N;j++){
if(j == x || adjMatrix[i][j] == -1) continue;
if(dsu_find(i) != dsu_find(j)){
dsu_join(i,j);
arestas_dsu.push_back(adjMatrix[i][j]);
}
}
}
vector<vi> arestas_faltam;
vi qual_pos;
for(int i = 0;i<N;i++){
if(i == x || dsu_find(i) != i) continue;
vi novo_cjt;
for(int j = 0;j<N;j++){
if(j == x || adjMatrix[x][j] == -1) continue;
if(dsu_find(j) == dsu_find(i)) novo_cjt.push_back(adjMatrix[x][j]);
}
qual_pos.push_back(arestas_dsu.size());
arestas_dsu.push_back(novo_cjt[0]);
arestas_faltam.push_back(novo_cjt);
}
for(int i = 0;i<arestas_faltam.size();i++){
int maxv = 0;
vi resultados;
for(int j = 0;j<arestas_faltam[i].size();j++){
arestas_dsu[qual_pos[i]] = arestas_faltam[i][j];
resultados.push_back(count_common_roads(arestas_dsu));
maxv = max(maxv,resultados.back());
}
for(int j = 0;j<arestas_faltam[i].size();j++){
if(resultados[j] == maxv) arestas_certas.push_back(arestas_faltam[i][j]);
}
}
}
vi find_roads(int n, vi u, vi v) {
memset(adjMatrix,-1,sizeof(adjMatrix));
N = n;
for(int i = 0;i<u.size();i++){
adjMatrix[u[i]][v[i]] = i;
adjMatrix[v[i]][u[i]] = i;
e1[i] = u[i];
e2[i] = v[i];
}
for(int i = 0;i<n;i++) processa(i);
sort(arestas_certas.begin(),arestas_certas.end());
arestas_certas.erase(unique(arestas_certas.begin(),arestas_certas.end()),arestas_certas.end());
return arestas_certas;
}
컴파일 시 표준 에러 (stderr) 메시지
simurgh.cpp: In function 'void processa(int)':
simurgh.cpp:61:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<arestas_faltam.size();i++){
~^~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:66:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0;j<arestas_faltam[i].size();j++){
~^~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:72:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0;j<arestas_faltam[i].size();j++){
~^~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'vi find_roads(int, vi, vi)':
simurgh.cpp:85:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<u.size();i++){
~^~~~~~~~~
# | 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... |