QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198297 | #3614. Math Trade | Zhou_JK | WA | 0ms | 3508kb | C++23 | 778b | 2023-10-03 12:31:40 | 2023-10-03 12:31:40 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
const int N=105;
int n;
int tot;
map<string,int>id;
int match[N*2];
bool vis[N*2];
int cnt,ans;
void dfs(int u)
{
cnt++;
vis[u]=true;
if(!match[u]) return;
if(!vis[match[u]]) dfs(match[u]);
else ans+=cnt;
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>n;
for(int i=1;i<=n;i++)
{
string name,s,t;
cin>>name>>s>>t;
if(!id.count(s)) id[s]=++tot;
if(!id.count(t)) id[t]=++tot;
match[id[s]]=id[t];
}
for(int i=1;i<=tot;i++)
if(!vis[i]) cnt=0,dfs(i);
if(ans==0) cout<<"No trades possible";
else cout<<ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
input:
4 Sally Clock Doll Steve Doll Painting Carlos Painting Clock Maria Candlestick Vase
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
4 Abby Bottlecap Card Bob Card Spoon Chris Spoon Chair Dan Pencil Pen
output:
No trades possible
result:
ok single line: 'No trades possible'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3480kb
input:
10 P0 I0 I0X P1 I1 I2 P2 I2 I9 P3 I3 I7 P4 I4 I6 P5 I5 I3 P6 I6 I1 P7 I7 I8 P8 I8 I5 P9 I9 I4
output:
9
result:
wrong answer 1st lines differ - expected: '5', found: '9'