Submission #499602

#TimeUsernameProblemLanguageResultExecution timeMemory
499602LoboSenior Postmen (BOI14_postmen)C++17
0 / 100
9 ms13244 KiB
#include<bits/stdc++.h>
using namespace std;

/*for ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
*/

const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 550000

ii n, m, blk[maxn], lt[maxn];
vector<pair<ii,ii>> g[maxn], vlr;
vector<ii> vec, mark, nx;

void dfs(ii u) {
    vec.pb(u);
    while(g[u].size()) {
        ii v = g[u].back().fr;
        ii id = g[u].back().sc;
        g[u].pop_back();

        if(blk[id]) continue;

        blk[id] = 1;
        dfs(v);
        break;
    }
}

void solve() {
    cin >> n >> m;

    for(ii i = 1; i <= m; i++) {
        ii u, v; cin >> u >> v;

        g[u].pb(mp(v,i));
        g[v].pb(mp(u,i));
    }



    for(ii j = 1; j <= n; j++) {
        vec.clear();
        mark.clear();
        vlr.clear();
        nx.clear();
        dfs(j);

        vector<ii> chlt; //anotar mudancas no lt pra desfazer

        mark.resize(vec.size()+3,0);
        nx.resize(vec.size()+3,0);
        for(ii i = 1; i <= vec.size(); i++) {
            ii x = vec[i-1];
            // cout << x << " ";
            if(lt[x] != 0) {
                nx[lt[x]] = i;
                vlr.pb(mp(lt[x],i-1));
                lt[x] = 0;
            }
            else {
                lt[x] = i;
                chlt.pb(x);
            }
        }

        for(auto X : vlr) {
            ii l = X.fr;
            ii r = X.sc;
            // cout << l << " - " << r << endl;

            vector<pair<ii,ii>> ans;
            bool ok = true;
            for(ii i = l; i <= r; i++) {
                if(nx[i] == 0) {
                    ans.pb(mp(vec[i-1],i));
                }
                else {
                    if(nx[i] <= r) i = nx[i]-1;
                    else if(!mark[i]) ans.pb(mp(vec[i-1],i));
                    else ok = false;
                }
            }

            if(!ok) continue;

            // cout << ans.size() << " " << l << " " << r << endl;
            for(auto x : ans) {
                cout << x.fr << " ";
                mark[x.sc] = 1;
            }
            cout << endl;
        }

        for(auto x : chlt) {
            lt[x] = 0;
        }
    }

    


    
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);

    ii tt = 1;
    // cin >> tt;
    while(tt--) solve();

}

Compilation message (stderr)

postmen.cpp: In function 'void solve()':
postmen.cpp:67:25: warning: comparison of integer expressions of different signedness: 'ii' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(ii i = 1; i <= vec.size(); i++) {
      |                       ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...