| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 795920 | vjudge1 | Monthly railway pass (LMIO18_menesinis_bilietas) | C++17 | 654 ms | 88652 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
const int maxN = 1e6 + 10;
int n, m;
vector<int> v[maxN];
int cmp[maxN];
int a[maxN], b[maxN];
int other[maxN], tot[maxN];
int cur;
map<pii, bool> mapa;
void dfs(int x, int comp) {
cmp[x] = comp;
tot[comp]++;
for (int i: v[x]) {
if (!cmp[i]) {
dfs(i, comp);
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i<= m; i++) {
int x, y;
char ch;
scanf("%d %d %c",&x,&y, &ch);
if (ch == 'T') {
v[x].pb(y);
v[y].pb(x);
} else {
a[++cur] = x;
b[cur] = y;
}
}
int cmpCount = 0;
for (int i = 1; i <= n; i++) {
if (!cmp[i]) {
dfs(i, ++cmpCount);
}
}
if (cmpCount == 1) {
cout << n << endl;
return 0;
}
for (int i = 1; i <= cur; i++) {
if (cmp[a[i]] != cmp[b[i]]) {
int x = cmp[a[i]];
int y = cmp[b[i]];
pii edge = mp(x, y);
if (mapa[edge] == false) {
mapa[edge] = true;
other[x]++;
mapa[mp(y, x)] = true;
other[y]++;
}
}
}
int ans = 0;
for (int i = 1; i<= cmpCount; i++) {
if (other[i] == cmpCount - 1) ans+= tot[i];
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
