답안 #234106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234106 2020-05-23T06:34:31 Z Nightlight Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
524 ms 40184 KB
#include <bits/stdc++.h>
#define pii pair<int, bool>
using namespace std;

int N, M;
vector<pii> adj[500005];
int waktu;
int col[500005], col_sz[500005];
bool vis[500005];

void DFS(int u) {
  col[u] = waktu;
  col_sz[waktu]++;
  vis[u] = 1;
  for(pii now : adj[u]) {
    if(now.second == 1 || vis[now.first] == 1) continue;
    DFS(now.first);
  }
}

bool ketemu[500005];
int neigh[500005], p;
int cnt;

void DFS2(int u) {
  vis[u] = 1;
  for(pii now : adj[u]) {
    if(col[u] != col[now.first]) {
      if(ketemu[col[now.first]] == 0) {
        neigh[++p] = col[now.first];
        ketemu[col[now.first]] = 1;
        cnt += col_sz[col[now.first]];
      }
      continue;
    }
    if(vis[now.first] == 1) continue;
    DFS2(now.first);
  }
}

int ans;

void solve() {
  memset(vis, 0, sizeof(vis));
  for(int i = 1; i <= N; i++) {
    if(vis[i]) continue;
    DFS2(i);
//    cout << col[i] << " -> " << cnt << "\n";
    if(cnt + col_sz[col[i]] == N) {
      ans += col_sz[col[i]];
    }
    cnt = 0;
    for(int i = 1; i <= p; i++) {
      ketemu[neigh[i]] = 0;
    }
    p = 0;
  }
  printf("%d\n", ans);
}

int main() {
  scanf("%d %d", &N, &M);
  int u, v;
  char ty;
  for(int i = 1; i <= M; i++) {
    scanf("%d %d %c", &u, &v, &ty);
    adj[u].emplace_back(v, ty == 'A');
    adj[v].emplace_back(u, ty == 'A');
  }
  for(int i = 1; i <= N; i++) {
    if(vis[i]) continue;
    waktu++;
    DFS(i);
  }/*
  for(int i = 1; i <= N; i++) {
    cout << col[i] << " ";
  }
  cout << "\n";
  for(int i = 1; i <= waktu; i++) {
    cout << col_sz[i] << " ";
  }
  cout << "\n";*/
  solve();
  cin >> N;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &M);
   ~~~~~^~~~~~~~~~~~~~~~~
menesinis_bilietas.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %c", &u, &v, &ty);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 524 ms 40184 KB Output is correct
2 Correct 12 ms 12544 KB Output is correct
3 Correct 14 ms 12544 KB Output is correct
4 Correct 19 ms 16256 KB Output is correct
5 Correct 12 ms 12672 KB Output is correct
6 Correct 93 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16256 KB Output is correct
2 Correct 12 ms 12544 KB Output is correct
3 Correct 12 ms 12672 KB Output is correct
4 Correct 14 ms 12928 KB Output is correct
5 Correct 12 ms 12672 KB Output is correct
6 Correct 164 ms 24260 KB Output is correct
7 Correct 313 ms 40032 KB Output is correct
8 Correct 18 ms 13568 KB Output is correct
9 Correct 26 ms 13952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12544 KB Output is correct
2 Correct 12 ms 12544 KB Output is correct
3 Correct 13 ms 12672 KB Output is correct
4 Correct 13 ms 12800 KB Output is correct
5 Correct 15 ms 12928 KB Output is correct
6 Correct 14 ms 12800 KB Output is correct
7 Correct 12 ms 12672 KB Output is correct
8 Correct 12 ms 12672 KB Output is correct
9 Correct 15 ms 12928 KB Output is correct
10 Correct 11 ms 12544 KB Output is correct
11 Correct 12 ms 12672 KB Output is correct
12 Correct 12 ms 12544 KB Output is correct
13 Correct 12 ms 12672 KB Output is correct
14 Correct 12 ms 12672 KB Output is correct
15 Correct 13 ms 12672 KB Output is correct
16 Correct 12 ms 12544 KB Output is correct
17 Correct 14 ms 12544 KB Output is correct
18 Correct 12 ms 12544 KB Output is correct
19 Correct 12 ms 12672 KB Output is correct
20 Correct 14 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12544 KB Output is correct
2 Correct 12 ms 12544 KB Output is correct
3 Correct 13 ms 12672 KB Output is correct
4 Correct 13 ms 12800 KB Output is correct
5 Correct 15 ms 12928 KB Output is correct
6 Correct 14 ms 12800 KB Output is correct
7 Correct 12 ms 12672 KB Output is correct
8 Correct 12 ms 12672 KB Output is correct
9 Correct 15 ms 12928 KB Output is correct
10 Correct 11 ms 12544 KB Output is correct
11 Correct 12 ms 12672 KB Output is correct
12 Correct 12 ms 12544 KB Output is correct
13 Correct 12 ms 12672 KB Output is correct
14 Correct 12 ms 12672 KB Output is correct
15 Correct 13 ms 12672 KB Output is correct
16 Correct 22 ms 13824 KB Output is correct
17 Correct 184 ms 27000 KB Output is correct
18 Correct 62 ms 17784 KB Output is correct
19 Correct 77 ms 19704 KB Output is correct
20 Correct 51 ms 16632 KB Output is correct
21 Correct 94 ms 19576 KB Output is correct
22 Correct 12 ms 12544 KB Output is correct
23 Correct 14 ms 12544 KB Output is correct
24 Correct 12 ms 12544 KB Output is correct
25 Correct 12 ms 12672 KB Output is correct
26 Correct 14 ms 12928 KB Output is correct
27 Correct 12 ms 12672 KB Output is correct
28 Correct 18 ms 13568 KB Output is correct
29 Correct 26 ms 13952 KB Output is correct
30 Correct 93 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12544 KB Output is correct
2 Correct 12 ms 12544 KB Output is correct
3 Correct 13 ms 12672 KB Output is correct
4 Correct 13 ms 12800 KB Output is correct
5 Correct 15 ms 12928 KB Output is correct
6 Correct 14 ms 12800 KB Output is correct
7 Correct 12 ms 12672 KB Output is correct
8 Correct 12 ms 12672 KB Output is correct
9 Correct 15 ms 12928 KB Output is correct
10 Correct 11 ms 12544 KB Output is correct
11 Correct 12 ms 12672 KB Output is correct
12 Correct 12 ms 12544 KB Output is correct
13 Correct 12 ms 12672 KB Output is correct
14 Correct 12 ms 12672 KB Output is correct
15 Correct 13 ms 12672 KB Output is correct
16 Correct 22 ms 13824 KB Output is correct
17 Correct 184 ms 27000 KB Output is correct
18 Correct 62 ms 17784 KB Output is correct
19 Correct 77 ms 19704 KB Output is correct
20 Correct 51 ms 16632 KB Output is correct
21 Correct 94 ms 19576 KB Output is correct
22 Correct 524 ms 40184 KB Output is correct
23 Correct 12 ms 12544 KB Output is correct
24 Correct 14 ms 12544 KB Output is correct
25 Correct 19 ms 16256 KB Output is correct
26 Correct 12 ms 12544 KB Output is correct
27 Correct 12 ms 12672 KB Output is correct
28 Correct 14 ms 12928 KB Output is correct
29 Correct 12 ms 12672 KB Output is correct
30 Correct 164 ms 24260 KB Output is correct
31 Correct 313 ms 40032 KB Output is correct
32 Correct 49 ms 15608 KB Output is correct
33 Correct 362 ms 30844 KB Output is correct
34 Correct 234 ms 22776 KB Output is correct
35 Correct 18 ms 13568 KB Output is correct
36 Correct 26 ms 13952 KB Output is correct
37 Correct 93 ms 19960 KB Output is correct