Submission #570439

#TimeUsernameProblemLanguageResultExecution timeMemory
570439uroskSenior Postmen (BOI14_postmen)C++14
0 / 100
7 ms12080 KiB
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x)
// __builtin_clz(x) vodece nule
// __builtin_clzll(x)
// __builtin_ctz(x) nule na pocetku
// __builtin_ctzll(x)
// 2000000011
// 2000000033
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"---------------------------\n"
#define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}

void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
ll lcm(ll a,ll b){
   return (a/gcd(a,b))*b;
}
ll add(ll a,ll b){
	a+=b;
	if(a<0) a+=mod;
	if(a>=mod) a%=mod;
	return a;
}
ll mul(ll a,ll b){return(a*b)%mod;}
#define maxn 500005
vector<ll> g[maxn];
ll n,m;
bool vis[maxn];
vector<ll> ans;
ll it[maxn];
void euler(ll u){
    while(it[u]<sz(g[u])){
        ll s = g[u][it[u]++];
        ll j = g[u][it[u]++]>>32LL;
        s = s&((1<<32LL)-1);
        if(vis[j]) continue;
        euler(s);
    }
    ans.pb(u);
}
void tc(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n >> m;
    for(ll i = 1;i<=m;i++){
        ll x,y; cin >> x >> y;
        g[x].pb(y+(i<<32LL));
        g[y].pb(x+(i<<32LL));
    }
    for(ll i = 1;i<=n;i++) if(!vis[i]) euler(i);
    fill(vis,vis+n+1,0);
    vector<ll> v;
    vector<ll> w;
    //ceri(ans,0,sz(ans)-1);
    for(ll x : ans){
        if(vis[x]==1){
            while(v.back()!=x){
                w.pb(v.back());
                v.popb();
            }
            w.pb(x);
            for(ll y : w){
                vis[y] = 0;
                cout<<y<< " ";
            }
            cout<<endl;
            w.clear();
            vis[x] = 1;
        }else vis[x] = 1,v.pb(x);
    }
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	//setIO("lol");
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}
/*
10 15
1 3
5 1
2 3
9 2
3 4
6 3
4 5
7 4
4 8
5 7
8 5
6 7
7 8
8 10
10 9

*/

Compilation message (stderr)

postmen.cpp: In function 'void euler(int)':
postmen.cpp:77:29: warning: right shift count >= width of type [-Wshift-count-overflow]
   77 |         ll j = g[u][it[u]++]>>32LL;
postmen.cpp:78:18: warning: left shift count >= width of type [-Wshift-count-overflow]
   78 |         s = s&((1<<32LL)-1);
      |                 ~^~~~~~
postmen.cpp: In function 'void tc()':
postmen.cpp:89:21: warning: left shift count >= width of type [-Wshift-count-overflow]
   89 |         g[x].pb(y+(i<<32LL));
      |                    ~^~~~~~
postmen.cpp:90:21: warning: left shift count >= width of type [-Wshift-count-overflow]
   90 |         g[y].pb(x+(i<<32LL));
      |                    ~^~~~~~
postmen.cpp: In function 'void setIO(std::string)':
postmen.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:48:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...