# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1096934 | ivaziva | Monthly railway pass (LMIO18_menesinis_bilietas) | C++14 | 429 ms | 85816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000001
int n,m;
vector<int> adj[2][MAXN];
int komp[MAXN],siz[MAXN],tren=0;
bool pos[MAXN];
vector<int> koren;
set<int> komponente;
void dfs(int node)
{
pos[node]=true;komp[node]=tren;siz[tren]++;
for (int sled:adj[0][node])
{
if (pos[sled]==true) continue;
else dfs(sled);
}
}
void dfs1(int node)
{
pos[node]=true;
for (int sled:adj[1][node])
{
if (komp[sled]==komp[node]) continue;
else komponente.insert(komp[sled]);
}
for (int sled:adj[0][node])
{
if (pos[sled]==true) continue;
else dfs1(sled);
}
}
int main()
{
cin>>n>>m;
for (int i=1;i<=m;i++)
{
int x,y;cin>>x>>y;char c;cin>>c;
if (c=='T') {adj[0][x].push_back(y);adj[0][y].push_back(x);}
else {adj[1][x].push_back(y);adj[1][y].push_back(x);}
}
koren.push_back(0);
for (int i=1;i<=n;i++)
{
if (pos[i]==true) continue;
else {koren.push_back(i);tren++;dfs(i);}
}
for (int i=1;i<=n;i++) pos[i]=false;
int ans=0;
for (int i=1;i<=tren;i++)
{
dfs1(koren[i]);
if (komponente.size()==tren-1) ans+=siz[i];
komponente.clear();
}
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... |