Submission #479677

# Submission time Handle Problem Language Result Execution time Memory
479677 2021-10-12T20:34:22 Z hidden1 Garbage (POI11_smi) C++14
20 / 100
523 ms 73396 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
    printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
    const char* end = strchr(names + 1, ',');
    cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
    printDebug(end, args...);
}
 
const int MAX_N = 1e5 + 10;
vector<pair<int, int> > g[MAX_N];
int n, m;
bool used[MAX_N];
vector<int> eul;
bool seen[MAX_N];

void dfs(int x) {
    eul.push_back(x);
    seen[x] = true;
    for(auto it : g[x]) {
        if(used[it.second]) {continue;}
        used[it.second] = true;
        dfs(it.first);
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i < m; i ++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(c != d) {
            g[a].push_back({b, i});
            g[b].push_back({a, i});
        }
    } 
    for(int i = 1; i <= n; i ++) {
        if(g[i].size() % 2 == 1) {
            cout << "NIE" << endl;
            return 0;
        }
    }
    for(int i = 1; i <= n; i ++) {
        if(!seen[i]) {
            dfs(i);
        }
    }
    stack<int> st;
    vector<vector<int> > ans;
    for(auto el : eul) {
        if(seen[el]) {
            st.push(el);
            seen[el] = false;
        } else {
            vector<int> nowCycle = {};
            nowCycle.push_back(el);
            while(st.top() != el) {
                auto tp = st.top(); st.pop();
                seen[tp] = true;
                nowCycle.push_back(tp);
            }
            nowCycle.push_back(el);
            ans.push_back(nowCycle);
        }
    }

    cout << ans.size() << endl;
    for(auto &it : ans) {
        cout << it.size() - 1 << " ";
        for(auto &el : it) {
            cout << el << " ";
        }
        cout << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB nie zgadzaja sie cykle pokrywajace
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2816 KB nie zgadzaja sie cykle pokrywajace
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3020 KB Output is correct
2 Correct 3 ms 2812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3020 KB nie zgadzaja sie cykle pokrywajace
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 3660 KB nie zgadzaja sie cykle pokrywajace
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 68 ms 20248 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 287 ms 42100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 455 ms 60732 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 523 ms 73396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -