QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322915#39. Love Polygonjames1BadCreeper25 139ms16104kbC++141.2kb2024-02-07 22:49:272024-02-07 22:49:29

Judging History

你现在查看的是最新测评结果

  • [2024-02-07 22:49:29]
  • 评测
  • 测评结果:25
  • 用时:139ms
  • 内存:16104kb
  • [2024-02-07 22:49:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5; 

int n, tot, to[N], deg[N], vis[N]; 
map<string, int> mp; 

int dfs(int x) {
    if (vis[x]) return 0; vis[x] = 1; 
    return dfs(to[x]) + 1; 
}

int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n; int ans = 0; 
    if (n & 1) return cout << "-1\n", 0; 
    for (int i = 1; i <= n; ++i) {
        string s, t; cin >> s >> t; 
        int S = (mp[s] ? mp[s] : mp[s] = ++tot); 
        int T = (mp[t] ? mp[t] : mp[t] = ++tot); 
        if (S != T) to[S] = T; 
        else ++ans, vis[S] = 1; 
    }
    for (int i = 1; i <= n; ++i) if (i == to[to[i]]) vis[i] = vis[to[i]] = 1; 
    for (int i = 1; i <= n; ++i) if (!vis[i]) ++deg[to[i]]; 

    queue<int> q; 
    for (int i = 1; i <= n; ++i) if (!vis[i] && deg[i] == 0) q.push(i); 
    while (!q.empty()) {
        int u = q.front(), v = to[u]; q.pop(); ++ans; 
        if (!vis[v]) {
            vis[v] = 1; 
            if (!--deg[to[v]] && !vis[to[v]]) q.push(to[v]); 
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i]) {
        int k = dfs(i); 
        if (k > 2) ans += (k + 1) / 2; 
    }
    cout << ans << '\n'; 
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7700kb

input:

20
dqwdlhkyrs faettwvbvz
ymvulechrl mpccwwrdsn
kngwmfcpnu hsyztxtomt
nuobkdfeny pnowootaqk
faettwvbvz ymvulechrl
jnblidnvao dnumkgrmtu
tigdjzmvir kngwmfcpnu
aywoujmlqx jnblidnvao
mpccwwrdsn rpbozfibsk
hcoxgkfnyr hyowdbkmcl
rpbozfibsk higpdaadwg
aeffzovrro dqwdlhkyrs
pnowootaqk ivjjxerjey
ivjjxerjey ...

output:

11

result:

wrong answer 1st lines differ - expected: '10', found: '11'

Subtask #2:

score: 25
Accepted

Test #16:

score: 25
Accepted
time: 0ms
memory: 3536kb

input:

2
brtmorckba brtmorckba
hzfqflfczp hzfqflfczp

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

4
vjaqtftnon adllamfood
wyqcsliens ixdxpbqywl
adllamfood vjaqtftnon
ixdxpbqywl wyqcsliens

output:

0

result:

ok single line: '0'

Test #18:

score: 0
Accepted
time: 1ms
memory: 7688kb

input:

6
ktfvywpjup ktfvywpjup
tougwqukic tougwqukic
bcriexqiup bbntpotayn
asqqdrhaut bcriexqiup
nodottwuwp asqqdrhaut
bbntpotayn nodottwuwp

output:

4

result:

ok single line: '4'

Test #19:

score: 0
Accepted
time: 129ms
memory: 16104kb

input:

100000
kgzbaurhcw ieqkdzugxd
zdxapkdjyr ciryujuxea
zyaqfekliw zxiihylife
ygtokuvvau ycfwnpmekw
sfiqaijtop otnyitiyeg
edpgyvetub jskgenvrvm
bmsnfmpsci pzvvrlinut
ykvxjvaqwr wqpshqhljz
uyfsibjfbd nkmfuwojqj
wrvqkoivgn wqrdimjzhb
bgdofpjpiz zoohnreboe
vmvfvetmsa kpedhehqpa
rmwlrafvcx vsmqfjmfih
znyyynz...

output:

50003

result:

ok single line: '50003'

Test #20:

score: 0
Accepted
time: 139ms
memory: 15800kb

input:

100000
sljvuoslhg bhyqlublzg
cfxxvgnnoq ayxbfufakl
myseqyebki eypbrtpjko
mndnwojhmk usimdabrad
vcmqcjborp igeuuswqxh
agylwajluy pcgksmeyjx
nvadtztpyb fhpvnvwqdt
fzvxrbvsjv utdlcrpzoi
qhrhumrufu dfqtvqlyvv
hyxzofkkwx fxbpvicgiz
breijvspxw jrjxiwgjgp
foqtsvcadg zammkqmvly
yrotnpxxrc qzndpgizth
mdntxfn...

output:

53306

result:

ok single line: '53306'

Test #21:

score: 0
Accepted
time: 131ms
memory: 15732kb

input:

100000
mqjejqtaim adynnluflo
tyuqttwunn bxgpxckyuv
cswqvvyviu wrguicwvnh
jsdhzxysmq rixnaqziey
vvrorndcjp yvvkzyvvgw
tlejurlumo brzrgdwmmd
modktlracv icaveptbof
xpztyndoit hwnjewgpko
rpxxxcawkm qjihyslolw
yzaswiwijm ltwvnijrfm
jbbgbjviab loxddiqwta
egsiepumaq kkxrpnqacm
xyetwffbqz spdzrzlduy
dvbjfzu...

output:

50000

result:

ok single line: '50000'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

99999
bhfudjyvco wzpbznarxh
lwdnazaoan kpkbwqxbfa
kpusnkurzp bpaucbpkfd
pcjwctjtuf sfnmwzveoi
uacvxzutfd rpqsvgnrbo
hnbsnwoyqo yzklbcbidg
dodsdgxozf xjshbafyrk
armalzfzzt mkdlexlmer
fsbdccbfdl vhdgrssoci
nyxnxjpono bnzqopdcir
nlyztlkerf mqhvheymxt
glfanewehr kmxmsdnlnf
xgkvzxpcso cmojrnipzo
huwgbptz...

output:

-1

result:

ok single line: '-1'

Subtask #3:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 138ms
memory: 15948kb

input:

100000
jochpzryhw kbrhxbvsgu
jfejdndufv ksouutcmzy
binlnitgyw wytuxoixio
hiiynmdoib mvxdjnxqmg
zrvfpttvaa fvaaakyglq
ryxhlcfoqe aswjlllecb
mkpboggifp norydruurd
vcvanmomxs auokoxrbjj
jgnmcqebhk bcknjfemkm
qpbahdmzqn cxfqoudzfg
hxiqyqihmp dqjvhwgldq
tnigwwuiiz qxiukoymms
efpbwtcqfs dxiwctzkux
rajtwbx...

output:

54654

result:

wrong answer 1st lines differ - expected: '54104', found: '54654'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%