이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>tConn;
vector<vector<int>>aConn;
int N,M;
struct Group{
vector<int>miestai;
vector<int>connections;
void mergeGroup(Group g){
for(int m:g.miestai) miestai.push_back(m);
for(int c:g.connections)
if(find(connections.begin(), connections.end(), c)==connections.end())
connections.push_back(c);
}
bool hasCity(int city){
return (find(miestai.begin(), miestai.end(), city)!=miestai.end());
}
bool hasConnection(int conn){
return (find(connections.begin(), connections.end(), conn)!=connections.end());
}
};
int find_group_with_city(vector<Group> grupes, int cityId) {
for (int i = 0; i < grupes.size(); i++) {
if(grupes[i].hasCity(cityId))return i;
}
return -1;
}
void create_group(int cityId, vector<Group> & grupes) {
Group g;
g.miestai.push_back(cityId);
grupes.push_back(g);
}
void change_ref(int from, int to, vector<Group> & grupes){
for(Group g: grupes){
for(int c: g.connections){
if(c==from)c=to;
}
}
}
//N-miestu skaicius M-transporto linijos
void dumpGroups(vector<Group> grupes){
for (Group g : grupes) {
for (int m : g.miestai) {
cout<<m<<" ";
}
cout<<" ----> ";
for (int c : g.connections) {
cout<<c<<" ";
}
cout<<endl;
}
}
int main() {
cin >> N >> M;
int a, b;
char T;
tConn.resize(N);
aConn.resize(N);
for (int i = 0; i < M; i++) {
cin >> a >> b >> T;
if(T=='T'){
tConn[a-1].push_back(b-1);
tConn[b-1].push_back(a-1);
}
else{
aConn[a-1].push_back(b-1);
aConn[b-1].push_back(a-1);
}
}
vector<Group>grupes;
vector<int>sk_grupe(N, -1);
queue<int> nextToCheck;
for (int i = 0; i < N; i++) {
if (sk_grupe[i] == -1) {
grupes.push_back(Group());
nextToCheck.push(i);
while (!nextToCheck.empty()) {
if (sk_grupe[nextToCheck.front()] == -1) {
sk_grupe[nextToCheck.front()] = grupes.size() - 1;
grupes[grupes.size() - 1].miestai.push_back(nextToCheck.front());
for (int c : tConn[nextToCheck.front()]) {
nextToCheck.push(c);
}
}
nextToCheck.pop();
}
}
}
for(Group & g: grupes){
for (int m : g.miestai) {
for (int c : aConn[m]) {
if (!g.hasConnection(sk_grupe[c])){
g.connections.push_back(sk_grupe[c]);
}
}
}
}
int m=0;
for (Group g : grupes) {
if(g.connections.size()==grupes.size()-1){
//turi visas grupes
m+=g.miestai.size();
}
}
cout<<m<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
menesinis_bilietas.cpp: In function 'int find_group_with_city(std::vector<Group>, int)':
menesinis_bilietas.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Group>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 0; i < grupes.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... |