QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416044#6765. Don't Really Like How The Story EndsjohntimeWA 71ms3600kbC++141.2kb2024-05-21 15:16:102024-05-21 15:16:11

Judging History

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

  • [2024-05-21 15:16:11]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:3600kb
  • [2024-05-21 15:16:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
void dfs(int u,int d,vector<set<int>> &g,vector<bool> &vis){
    if(g[u].size()){
        bool flag=true;
        for(auto v:g[u]){
            if(vis[v])continue;
            if(v==u+1){
                vis[v]=true;
                dfs(v,d+1,g,vis);
                flag=false;
            }else{
                vis[v]=true;
                dfs(v,d+1,g,vis);
            }
        }
        if(flag){
            if(u==n)return;
            ans+=1;
            vis[u+1]=true;
            dfs(u+1,d+1,g,vis);
        }
    }
}
void work(){
    cin>>n>>m;
    ans=0;
    vector<set<int>> g(n+1);
    vector<bool> vis(n+1);
    for(int i=1,u,v;i<=m;i++){
        cin>>u>>v;
        g[min(u,v)].insert(max(u,v));
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            vis[i]=true;
            dfs(i,0,g,vis);
            if(i!=1)ans++;
        }
    }
    cout<<ans<<endl;
}
int main(){
    int t;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>t;
    while(t--){
        work();
    }
}
//
// Created by johntime on 24-5-20.
//

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

3
2 3
1 1
1 2
2 1
4 1
1 4
4 2
1 2
3 4

output:

0
2
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 71ms
memory: 3580kb

input:

117747
3 7
2 1
3 3
1 3
1 1
3 2
1 1
3 1
4 8
2 3
4 3
3 2
4 2
1 3
2 1
4 3
2 4
3 4
2 3
2 2
3 3
1 1
2 5
1 1
2 2
2 2
1 2
2 2
3 7
2 1
1 2
3 3
3 2
1 2
3 3
3 2
4 5
1 2
3 3
4 4
1 4
2 1
3 1
3 2
1 3
1 1
1 1
1 1
1 6
1 1
1 1
1 1
1 1
1 1
1 1
5 4
2 1
2 5
1 3
3 2
4 7
1 1
2 4
3 2
1 1
1 1
4 2
2 3
5 8
3 3
2 2
4 2
1 4
1...

output:

0
0
1
0
0
2
1
0
0
1
1
2
0
0
4
0
2
0
1
0
0
3
0
0
0
2
2
1
1
0
0
0
3
0
5
1
3
0
1
1
3
2
2
3
0
0
1
2
0
2
0
2
3
0
0
2
0
0
1
1
0
4
0
3
0
0
1
0
0
3
2
0
0
0
1
0
4
3
0
1
3
1
1
1
0
2
1
4
0
1
2
0
0
0
3
0
0
3
2
0
2
0
0
0
1
0
0
0
0
0
0
4
0
0
0
0
1
0
3
0
2
1
0
2
1
0
0
3
0
1
0
0
0
3
1
1
2
2
0
1
0
1
0
0
3
1
1
0
0
0
...

result:

wrong answer 6th lines differ - expected: '1', found: '2'