General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
94260114 Practice:
JAMMY
605B - 39 GNU C++11 Accepted 202 ms 1956 KB 2020-09-30 07:42:53 2020-09-30 07:42:53
 
 
→ Source
#include <bits/stdc++.h>
using namespace std;
vector <int> inc(100005);
bool comp(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.first!=b.first)
    return a.first<b.first;
    else 
    return inc[a.second]>inc[b.second];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector <pair<int,int>> edge(m+1);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        inc[i]=b;
        edge[i]={a,i};
    }
    sort(edge.begin()+1,edge.end(),comp);
    int from=2,to=3,last=1;
    vector <pair<int,int>> ans(m+1);
    bool flag=true;
    for(int i=1;i<=m && flag;i++)
    {
        int val=inc[edge[i].second];
        if(val)
        {
            last++;
            ans[edge[i].second]={1,last};
        }
        else
        {
            if(from==to)
            {
                from=2;
                to++;
            }
            if(to>last)
            flag=false;
            else
            {
                ans[edge[i].second]={from,to};
                from++;
            }
        }
    }
    if(flag)
    {
        for(int i=1;i<=m;i++)
        cout<<ans[i].first<<" "<<ans[i].second<<"\n";
    }
    else
    cout<<-1;
    return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details