답안 #500362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500362 2021-12-30T19:29:17 Z GenericAccount Monthly railway pass (LMIO18_menesinis_bilietas) C++17
75 / 100
3000 ms 79688 KB
#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());
    }
};




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(int i=0; i<grupes.size(); i++){
    for (int m : grupes[i].miestai) {
      for (int c : aConn[m]) {
        if (!grupes[i].hasConnection(sk_grupe[c])&&sk_grupe[c]!=i){
          grupes[i].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;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Group>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for(int i=0; i<grupes.size(); i++){
      |                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 483 ms 29452 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 78 ms 61020 KB Output is correct
5 Correct 2 ms 1928 KB Output is correct
6 Correct 113 ms 4632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 61020 KB Output is correct
2 Correct 2 ms 1928 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 588 KB Output is correct
6 Correct 1959 ms 13768 KB Output is correct
7 Execution timed out 3067 ms 79688 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 588 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 6 ms 472 KB Output is correct
11 Correct 5 ms 424 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 8 ms 660 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 6 ms 472 KB Output is correct
6 Correct 5 ms 424 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 8 ms 660 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 392 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 4 ms 588 KB Output is correct
21 Correct 2 ms 1928 KB Output is correct
22 Correct 113 ms 4632 KB Output is correct
23 Correct 16 ms 1116 KB Output is correct
24 Correct 299 ms 10792 KB Output is correct
25 Correct 77 ms 3752 KB Output is correct
26 Correct 132 ms 5708 KB Output is correct
27 Correct 63 ms 3072 KB Output is correct
28 Correct 189 ms 7064 KB Output is correct
29 Correct 36 ms 3508 KB Output is correct
30 Correct 46 ms 3808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 6 ms 472 KB Output is correct
6 Correct 5 ms 424 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 8 ms 660 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 392 KB Output is correct
16 Correct 16 ms 1116 KB Output is correct
17 Correct 299 ms 10792 KB Output is correct
18 Correct 77 ms 3752 KB Output is correct
19 Correct 132 ms 5708 KB Output is correct
20 Correct 63 ms 3072 KB Output is correct
21 Correct 189 ms 7064 KB Output is correct
22 Correct 483 ms 29452 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 78 ms 61020 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 4 ms 588 KB Output is correct
29 Correct 2 ms 1928 KB Output is correct
30 Correct 1959 ms 13768 KB Output is correct
31 Execution timed out 3067 ms 79688 KB Time limit exceeded