QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106298#5160. Kebab PizzajoesmittyWA 4ms5852kbC++144.6kb2023-05-17 12:09:002023-05-17 12:09:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-17 12:09:01]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5852kb
  • [2023-05-17 12:09:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
 
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
//#define endl '\n';
#define sz(x) (int)(x).size()
 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
 
template <typename T>
void pr(vector<T> &v) {
    FOR(i, 0, sz(v)) cout << v[i] << " ";
    cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
    FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
    cin >> x;
}
template <typename T>
void re(vector<T> &a) {
    FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
    re(first);
    re(rest...);
}
template <typename T>
void pr(T x) {
    cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
    cout << first << " ";
    pr(rest...);
    cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
    cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
 
const ll MOD  =  998244353;
#define inf 1e18;
#define INF INT_MAX;
 
long double PI = 4*atan(1);
long double eps = 1e-12;


int n,k;
int m;
int p;
vector<pii> edges;

int deg[100010] = {};
vi adj[100010] = {};
vi verts;
int vis[100010] = {};
int nvis = 0;
int numdeg1  = 0;

void dfs(int u) {
    
    if(adj[u].size() == 1) numdeg1--;

    for(auto v : adj[u]) {
        if(!vis[v]) {
            vis[v] = 1;
            nvis++;
            dfs(v);
        }
    }

}

int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    // freopen("promote.in", "r", stdin);
	// freopen("promote.out", "w", stdout);
    #ifdef DEBUG
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif 

    cin >> n >> k;

    FOR(i,0,n) {
        int u,v; cin >> u >> v;
        if(u > v) swap(u,v);
        edges.pb({u,v});
        verts.pb(u); 
        verts.pb(v);
    }
    sort(all(verts));
    verts.resize(unique(all(verts)) - verts.begin());
    p = verts.size();

    for(auto &e : edges) {
        e.ff = lower_bound(all(verts), e.ff) - verts.begin();
        e.ss = lower_bound(all(verts), e.ss) - verts.begin();
    }
    edges.resize(unique(all(edges)) - edges.begin());


    m = edges.size();

    for(auto e : edges) {
        deg[e.ff]++;
        deg[e.ss]++;
    }


    for(auto e : edges) {
        bool good = true;
        if(deg[e.ff] == 1 && deg[e.ss] > 1) good = false;
        if(deg[e.ff] > 1 && deg[e.ss] == 1) good = false;

        if(good) {
            if(e.ss != e.ff) {
                adj[e.ff].pb(e.ss);
                adj[e.ss].pb(e.ff);
            }
        } else {
            if(deg[e.ff] == 1) {
                if(vis[e.ff] == 0) {
                nvis++; 
                vis[e.ff] = 1;
                }
            }
            if(deg[e.ss] == 1) {
                if(vis[e.ss] == 0) {
                    nvis++;
                    vis[e.ss] = 1;
                }
            }
        }
        
    }

    // FOR(i,0,p) {
    //     cout << i << ": ";
    //     pr(adj[i]);
    // }


    FOR(i,0,p) {
        if(adj[i].size() > 2) {
            cout << "impossible" << endl;
            return 0;
        } else if(adj[i].size() == 1) {
            numdeg1++;
        }
    }


    int rem = p - nvis;

    FOR(i,0,p) {
        if(!vis[i] && adj[i].size() > 0) {
            int pvis = nvis;
            vis[i] = 1;
            nvis++;
            int prenum1 = numdeg1;
            dfs(i);
            // cycle
            if(numdeg1 == prenum1 && nvis - pvis != rem) {
                cout << "impossible" << endl;
                return 0;
            }
        }
    }

    cout << "possible" << endl;







    


    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    // cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #2:

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #3:

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

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #5:

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

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #7:

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

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #8:

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

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 3ms
memory: 5652kb

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 3ms
memory: 5596kb

input:

3 4
1 2
2 3
3 1

output:

possible

result:

ok single line: 'possible'

Test #11:

score: -100
Wrong Answer
time: 4ms
memory: 5832kb

input:

4 3
1 2
2 3
3 1
1 2

output:

impossible

result:

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