QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303873#7107. Chaleurkevinshan#WA 602ms20164kbC++172.2kb2024-01-13 03:25:592024-01-13 03:26:00

Judging History

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

  • [2024-01-13 03:26:00]
  • 评测
  • 测评结果:WA
  • 用时:602ms
  • 内存:20164kb
  • [2024-01-13 03:25:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
const int xm[4] = {-1, 1, 0, 0};
const int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll POW = 9973;

const int MX = 1e5+5;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define For(i,a) FOR(i,0,a)

vector<int> adj[MX];
void solve() {
    int n,m;cin>>n>>m;
    For(i,n) {
        adj[i].clear();
    }
    For(i,m) {
        int u,v;cin>>u>>v;u--;v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    set<int> ins, out;
    For(i,n) {
        ins.insert(i);
    }
    For(i,n) {
        if (adj[i].size() <= 1) {
            ins.erase(i);
            out.insert(i);
        }
    }

    if (ins.size() == 1) {
        int x = *ins.begin();
        cout << adj[x].size() << ' ';
    } else if(ins.size()==2){
        cout << m << ' ';
    } else {
        cout << 1 << ' ';
    }

    int frees = 0;
    for(int x:ins) {
        bool flag = false;
        for(int y:adj[x]) {
            if (out.count(y)) {
                flag = true;
            }
        }
        if (!flag) {
            frees++;
        }
    }

    // cout << frees << " " << ins.size() << '\n';
    if (ins.size() <= 1) {
        if (ins.size() == 0) {
            cout << 2 << '\n';
        } else {
            int x = *ins.begin();
            if (adj[x].size() == 1 ){
                cout << 2 << '\n';
            } else {
                cout << 1 << '\n';
            }

        }
    } else {
        if (frees == 0) {
            cout << ins.size()+1 << '\n';
        } else {
            cout << frees << '\n';
        }
    }

}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int t;cin>>t;
    for(int i=0;i<t;i++) {
        solve();
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5856kb

input:

3
3 2
1 2
2 3
6 6
1 2
2 3
1 3
1 4
2 5
3 6
4 1
1 2

output:

2 1
1 4
1 2

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 602ms
memory: 20164kb

input:

2231
1 0
5 7
4 1
3 4
3 1
3 5
4 2
3 2
4 5
5 4
2 1
2 5
2 4
2 3
5 10
3 2
2 5
1 4
4 2
4 5
1 2
1 3
3 5
3 4
1 5
5 10
1 3
2 4
1 4
5 2
2 3
1 5
5 4
1 2
3 4
5 3
5 9
2 5
3 5
2 3
2 1
4 3
3 1
4 1
4 5
2 4
5 4
4 2
4 1
4 5
4 3
5 9
4 1
4 5
3 4
2 4
2 1
3 1
2 5
3 5
3 2
5 4
2 5
2 3
2 1
2 4
5 9
5 2
1 3
4 3
1 2
5 4
4 2
5...

output:

1 2
1 5
4 1
1 5
1 5
1 5
4 1
1 5
4 1
1 5
1 5
1 5
4 1
4 1
1 5
1 5
4 1
1 5
1 5
1 5
1 5
4 1
4 1
4 1
1 5
1 5
4 1
4 1
1 5
4 1
4 1
1 5
1 5
1 5
4 1
4 1
4 1
1 5
1 5
4 1
1 5
4 1
4 1
4 1
1 5
1 5
4 1
4 1
1 5
1 5
4 1
1 5
1 5
1 5
4 1
1 5
1 5
4 1
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
4 1
1 5
1 5
1 5
1 5
1 5
1 5
...

result:

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